System.out.println ()을 짧게 만드는 방법
더 짧은 표현을 사용하기 위해 lib를 찾을 수있는 System.out.println()
위치와 해당 lib를 어디에 배치해야하는지 조언하십시오 .
로깅 라이브러리
휠을 다시 발명하는 대신 로깅 라이브러리를 사용할 수 있습니다. Log4j는 예를 들어이 같은 다른 메시지에 대한 방법을 제공 할 것입니다 info()
, warn()
하고 error()
.
수제 방법
또는 단순히 println
자신 만의 방법을 만들고 호출하십시오.
void println(Object line) {
System.out.println(line);
}
println("Hello World");
IDE 키보드 단축키
IntelliJ IDEA 및 NetBeans :
사용자가 입력 sout
을 누른 다음을 누릅니다 TAB유형을, 그리고 System.out.println()
바로 이곳에서 커서로, 당신을 위해.
식:
입력 syso
한 다음 CTRL+ 를 누릅니다 SPACE.
다른
좋아하는 텍스트 편집기 / IDE 용 "스 니펫"플러그인 찾기
정적 임포트
import static java.lang.System.out;
out.println("Hello World");
JVM 언어 탐색
스칼라
println("Hello, World!")
그루비
println "Hello, World!"
자이 썬
print "Hello, World!"
JRuby
puts "Hello, World!"
클로저
(println "Hello, World!")
코뿔소
print('Hello, World!');
void p(String l){
System.out.println(l);
}
가장 짧습니다. 해봐
Java는 자세한 언어입니다.
3 일만에 이미 귀찮게된다면 스칼라와 같은 다른 언어를 배우는 것이 좋습니다.
scala> println("Hello World")
Hello World
느슨한 의미에서 이것은 짧은 표현을 가능하게하기 위해 "라이브러리"를 사용하는 것으로 간주됩니다.)
몇 가지 흥미로운 대안 :
옵션 1
PrintStream p = System.out;
p.println("hello");
옵션 2
PrintWriter p = new PrintWriter(System.out, true);
p.println("Hello");
대한 하게 IntelliJ IDEA의 유형 sout
을 누릅니다 Tab.
들어 이클립스 형 syso
누릅니다 Ctrl+ Space.
log4j 또는 JDK 로깅을 사용하면 클래스에서 정적 로거를 작성하고 다음과 같이 호출 할 수 있습니다.
LOG.info("foo")
Bakkal이 설명했듯이 키보드 단축키 netbeans
에 대해서는 도구-> 옵션-> 편집기-> 코드 템플릿으로 이동하여 자신의 단축키를 추가하거나 편집 할 수 있습니다.
에서 Eclipse
이 템플릿입니다.
My solution for BlueJ is to edit the New Class template "stdclass.tmpl" in Program Files (x86)\BlueJ\lib\english\templates\newclass and add this method:
public static <T> void p(T s)
{
System.out.println(s);
}
Or this other version:
public static void p(Object s)
{
System.out.println(s);
}
As for Eclipse I'm using the suggested shortcut syso + <Ctrl> + <Space>
:)
A minor point perhaps, but:
import static System.out;
public class Tester
{
public static void main(String[] args)
{
out.println("Hello!");
}
}
...generated a compile time error. I corrected the error by editing the first line to read:
import static java.lang.System.out;
package some.useful.methods; public class B { public static void p(Object s){ System.out.println(s); } }
package first.java.lesson; import static some.useful.methods.B.*; public class A { public static void main(String[] args) { p("Hello!"); } }
In Java 8 :
List<String> players = new ArrayList<>();
players.forEach(System.out::println);
Using System.out.println() is bad practice (better use logging framework) -> you should not have many occurences in your code base. Using another method to simply shorten it does not seem a good option.
참고URL : https://stackoverflow.com/questions/3320764/how-to-make-system-out-println-shorter
'IT story' 카테고리의 다른 글
Heroku 배포 오류 H10 (앱 충돌) (0) | 2020.07.12 |
---|---|
Java 배열에서 모든 숫자의 합계를 어떻게 찾습니까? (0) | 2020.07.12 |
숫자가 두 값 사이에 있는지 확인하는 방법은 무엇입니까? (0) | 2020.07.12 |
Gmail SMTP 디버그 : 오류“웹 브라우저를 통해 로그인하십시오” (0) | 2020.07.12 |
스택과 큐의 기본 차이점은 무엇입니까? (0) | 2020.07.12 |