Skip to content

Instantly share code, notes, and snippets.

@Loliver1224
Created March 11, 2021 14:11
Show Gist options
  • Save Loliver1224/962e3ea1c9360bf5c428229253bb66bf to your computer and use it in GitHub Desktop.
Save Loliver1224/962e3ea1c9360bf5c428229253bb66bf to your computer and use it in GitHub Desktop.
Javaにおけるprintlnの簡潔化
public class MyPrint {
public static void main(String[] args) {
println("Hello, world!");
}
void print(Object line) {
System.out.print(line);
}
void println(Object line) {
System.out.println(line);
}
}
import java.io.*;
public class PrintWriterTest {
// System.out.println()はデフォでオートフラッシュが有効なため低速
// PrintWriterを用いて自動フラッシュしないようにする
static PrintWriter out = new PrintWriter(System.out);
static void myout(Object t){out.println(t);}
static void flush(){out.flush();}
public static void main(String[] args) {
println("Hello");
// プログラム終了前にフラッシュを忘れないように!
flush();
// out.close()でも暗黙的にflushが呼ばれる
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment