Wreszcie dali w Java coś co pomaga w przypadku zapisywania wielolinijkowych tekstów (na marginesie w PHP to już było od wieków). Czy jest to użyteczny ficzer, jak zwykle to zależy. Czasami w sofcie potrzebujemy wydrukować na ekranie/konsoli, zapisać do pliku kilka-kilkadziesiąt linijek tekstu. Na pewno jest trochę bardziej czytelniej:
String oldJavaString = "Usage: route [-nNvee] [-FC] [] List kernel routing tables\n" +
" route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.\n" +
"\n" +
" route {-h|--help} [] Detailed usage syntax for specified AF.\n" +
" route {-V|--version} Display version/author and exit.\n" +
"\n" +
" -v, --verbose be verbose\n" +
" -n, --numeric don't resolve names\n" +
" -e, --extend display other/more information\n" +
" -F, --fib display Forwarding Information Base (default)\n" +
" -C, --cache display routing cache instead of FIB\n";
String newJavaString = """
Usage: route [-nNvee] [-FC] [] List kernel routing tables
route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.
route {-h|--help} [] Detailed usage syntax for specified AF.
route {-V|--version} Display version/author and exit.
-v, --verbose be verbose
-n, --numeric don't resolve names
-e, --extend display other/more information
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
""";
System.out.println("newJavaString = " + newJavaString);
System.out.println("oldJavaString = " + oldJavaString);
Ps. Jak widać ten formater kodu nie kojarzy poprawnie potrójnego cudzysłowia.
1 Pingback