1. ??? ??
?? ????? ??? ??? "?? ??" ????? ???????. "?? ??" ??? ?? ??? ??? ???? ???? ????. ??? ??? ???? ??? ? ??? ??? ??? ?? ??? ??? ??? ?? ??? ????? ?? ?? ?? ??? ????. ?? Java?? ??? ?????.
(?? ????: Java ???? ????)
??? ??? ???? ??? ? ?? ?? ???? ??(fall-through)? ?? ? ????? ???? ??? ????? ? ??? ????. , ??? ??? ??? ???? ? ????. ?? ?? ??? ???? ?? ??? ?? ??? ??? ??? ? ????.
var log = switch (event) { case PLAY -> "User has triggered the play button"; case STOP, PAUSE -> "User needs a break"; default -> { String message = event.toString(); LocalDateTime now = LocalDateTime.now(); yield "Unknown event " + message + " logged on " + now; } };
2. ??? ??
Java 13? ??? ?? ?? ?? ? ??? ??? ?????. ??? ??? ???? ?? ?? ??? ??? ???? ?? ??? ? ????. ? ??? Java 14?? ? ?? ?? ??? ???? ? ?? ?? ??? ????. ?? ??, ?? ? ???? ??? ????? ?? ??? ?? ??? ????? ???? ???? ? ? ????. ?? ??? HTML ?? ?????.
String html = "<HTML>" + "\n\t" + "<BODY>" + "\n\t\t" + "<H1>\"Java 14 is here!\"</H1>" + "\n\t" + "</BODY>" + "\n" + "</HTML>";
??? ??? ???? ? ????? ???? ? ????. ??? ??? ?? ? ? ??? ?????? ???? ?? ??? ??? ??? ? ????.
String html = """ <HTML> <BODY> <H1>"Java 14 is here!"</H1> </BODY> </HTML>""";
??? ??? ?? ??? ????? ? ???? ?????.
Java 14?? ? ?? ??? ????? ???? ?????????. ??, ??? s ????? ???? ???? ??? ??? ? ????. ??, ????? ???? ? ?? ?? ??? ???? ?? ??? ? ????. ??? ?? ? ?? ??? ?? ??? ?? ?? ?? ??? ???? ?? ? ????.
?? ??, ?? ?? ? ???? ???? ??? ??? ????.
String literal = "Lorem ipsum dolor sit amet, consectetur adipiscing " + "elit, sed do eiusmod tempor incididunt ut labore " + "et dolore magna aliqua.";
??? ???? ????? ???? ???? ??? ?? ??? ? ????.
String text = """ Lorem ipsum dolor sit amet, consectetur adipiscing \ elit, sed do eiusmod tempor incididunt ut labore \ et dolore magna aliqua.\ """;
(??? ???? ?? ??: java ??? ???? )
3. ????of? ?? ??
Java 14?? ???? ??? ???? ?????? ?? ??? ?? ????? ??? ??? ??? ????. ?? ??, ?? ???
if (obj instanceof Group) { Group group = (Group) obj; // use group specific methods var entries = group.getEntries(); }
? ???? ??? ???? ??? ?? ????? ? ????.
if (obj instanceof Group group) { var entries = group.getEntries(); }
??? ????? obj? Group ????? ??? obj? Group ??? ??? ???? ?? ??? ?????? ? ?? ?? ??? ?? ??? ?? ??? ?? ?? ??? ??? ? ????.
??? ??? ??? Java ?????? ???? ???? ??? ? ????.
JEP 305? ? ?? ??? ???? Joshua Bloch? ?? "Effective Java"? ?? ???? ??? ?? ? ?? ??? ?? ??? ?????.
@Override public boolean equals(Object o) { return (o instanceof CaseInsensitiveString) && ((CaseInsensitiveString) o).s.equalsIgnoreCase(s); }
? ???? ??? CaseInsensitiveString ?????. ?? ??? ???? ???? ??? ? ????. ??:
@Override public boolean equals(Object o) { return (o instanceof CaseInsensitiveString cis) && cis.s.equalsIgnoreCase(s); }
? ???? ??? ?? ???? ?? ??? ?? ?? ???? ??? ??? ? ??? ????. ?? ??? ????? ?? ??? ?? ???? ?? ??? ??? ? ?? ??? ??? ??? ???? ????. ??? ?? ???? ?? ???? ??? ???? ????? ?? ??? ????? ?? ??? ??? ?? instanceof ???? ?? ?????.
?, ? ???? ??? ?? ??? ?????. ??? ? ??? ??? ? ?? ?? ??? ?? ?? ???? ?? ????.
4. ??
? ?? ???? ??? ?????. ?? ??? ?? ???? ??? ????? ? ???? ??? ???? Java ??? ??? ??? ??? ???? ?? ??? ??? ???? ? ??? ? ? ????. ???? ?? ??? ???? ?? ?????. ?? ??? ??? ?? ?? ?? ???? ???? ????.
???? ??? ?? ??? ??? ???? BankTransaction? ?? ?? ?????. BankTransaction? ??? ???? ??, ??, ??? ? ?? ??? ?????. ???? ??? ? ???? ? ?? ??? ????:
Constructor, getter, ??? toString(), hashCode() ? equals() ??? ??? ??? ????? IDE? ?? ???? ???? ?? ??? ?????. ??? ?? BankTransaction ???? ??? ????.
public class BankTransaction {private final LocalDate date; private final double amount; private final String description; public BankTransaction(final LocalDate date, final double amount, final String description) { this.date = date; this.amount = amount; this.description = description; } public LocalDate date() { return date; } public double amount() { return amount; } public String description() { return description; } @Override public String toString() { return "BankTransaction{" + "date=" + date + ", amount=" + amount + ", description='" + description + '\'' + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BankTransaction that = (BankTransaction) o; return Double.compare(that.amount, amount) == 0 && date.equals(that.date) && description.equals(that.description); } @Override public int hashCode() { return Objects.hash(date, amount, description); } }
Java 14? ??? ???? ???? ??? ?? ???? ???? ??? ?????. ? ???? ??? ??? ???? ??? ??? ????. Record? equals, hashCode ? toString ???? ??? ?????. ??? BankTransaction ???? ??? ?? ????? ? ????.
public record BankTransaction(LocalDate date,double amount, String description) {}
???? ?? ??? ? getter ???? ?? equals, hashCode ? toString? ??? "????" ??? ? ????.
? ??? ????? ???? ???? ???? ??? ????? ???.
javac --enable-preview --release 14 BankTransaction.javarecord? ??? ????? ?????. ??? ??? ??? ?? ??? ? ????. ??? ??? ?? ???? ?? ?????? ?? ????? ????. ??? ??? ??? ?? ?????.
5. NullPointerException
一些人認為,拋出NullPointerException異常應該當做新的“Hello World”程序來看待,因為NullPointerException是早晚會遇到的。玩笑歸玩笑,這個異常的確會造成困擾,因為它經(jīng)常出現(xiàn)在生產(chǎn)環(huán)境的日志中,會導致調試非常困難,因為它并不會顯示原始的代碼。例如,如下代碼:
var name = user.getLocation().getCity().getName();
在Java 14之前,你可能會得到如下的錯誤:
Exception in thread "main" java.lang.NullPointerExceptionat NullPointerExample.main(NullPointerExample.java:5)
不幸的是,如果在第5行是一個包含了多個方法調用的賦值語句(如getLocation()和getCity()),那么任何一個都可能會返回null。實際上,變量user也可能是null。因此,無法判斷是誰導致了NullPointerException。
在Java 14中,新的JVM特性可以顯示更詳細的診斷信息:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Location.getCity()" because the return value of "User.getLocation()" is nullat NullPointerExample.main(NullPointerExample.java:5)
該消息包含兩個明確的組成部分:
后果:Location.getCity()無法被調用原因:User.getLocation()的返回值為null增強版本的診斷信息只有在使用下述標志運行Java時才有效:
-XX:+ShowCodeDetailsInExceptionMessages
下面是個例子:
java -XX:+ShowCodeDetailsInExceptionMessages NullPointerExample
在以后的版本中,該選項可能會成為默認。
這項改進不僅對于方法調用有效,其他可能會導致NullPointerException的地方也有效,包括字段訪問、數(shù)組訪問、賦值等。
? ??? java14? ??? ??? ??????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

Win7 Ultimate ??, Win7 Professional ??, Win7 Home ?? ?? ?? Win7 ??? ??? ??? ?? ??? ?? ????. ?? ???? Home ??? Ultimate ?? ???? ?? ?? ??? ???? ?? ????. ??? ??? Win7 Family Meal? Win7 Ultimate? ???? ?? ????????. 1. Different Home Basic Edition? ??? ???. ???? ??? ? ??? ???? ??? ?? ?? ???? ????? ??? ? ??? ???? ???? ? ????. Home Premium? ???? TV ????, ??, ??? ? ??? ?? ??? ??? ? ?? ??? ?????? ??? ?????. Ultimate Edition? ? ???? ?? ??? ???? Windows 7 Home Premium? ?? ?????? ??? ?? ??? ??? ????.

SpringMVC? ?? ?? ??: ??? ??? ??? ???? ?? ?? ??? ?????. SpringMVC? ???? MVC(Model-View-Controller) ???? ??? ?? ???? ?? ??? ??? ???? ? ??? ?? Java ?? ? ?????? ?? ????????. ? ??????. SpringMVC? ?? ??? ???? ??? ? ??????? ?? ????? ???? ??? ? ????. ? ????? SpringMVC? ? ?? ??? ??? ?????.

Golang(Go ??)?? ???? ??? ??? ??? ???, ???? ??? ???? ??? ??? ? ?? ????? ??? ??? ?????. ? ????? ??? ???? ?? ?? ??? ???? ??? ???? ?? ?? ??? ?????. ??? ??? ??? ?? ??? ??? ???? ????. Golang??? type ???? ?? ??? ??? ?? ??? ?? ??? ? ????. ???? ??? ??? ? ????.

???? ??? ???? ????? ??? ???? ???? ?????? ????. ? ? ???? ????? ??? Go ??? ?? ? ?? ?? ??? ?? ????. Go ??? ???? ????? ???? ?? ? ??? ????? ???????. ?? ???, ?? ???, ??? ??? ?? ??? ?? ?? ? ??, ???? ???, ???? ? ???? ?? ?????. ??? ?? ??? ??? Go ??? ??? ? ????. ??? Go ?? ??? ??? ? ?? ??? ??? ?? ???? ???. ??

5G? ? ?? ??? ??? ????. 1. ??, ?? ?? ???? 5G ????? ??? 4G ????? 10? ?????. 2. ?? ?? ??: 5G ????? ?? ??? ? ?? ???? ??? ?? ???? ????. 3. ??? ???, 5G ????? ??? ?? ??? ???? ?????(Internet of Everything)? ??? ??? ??? ????.

Java? ??? ??? ????. 1. ???? ??? ????. 2. ??? ? ?? ????? ?? ??? ? ????. 3. ??? ????? ??? ?? ???? ?? ?????. 4. ?? ???? ?? ??? ?? ?? ???? ??? ?? 5. ??? ???? ?? ?? ??? ???? ???. 6. ?? ??? ?? ??? ? ??? ??? ? ?? ??. 8. ?? ??? ?? ???? ??? ??? ? ????. 9. ??? ?? ????? ? ????? 10. ?? ?? ???.

C++ ???? ?? ??, const ??, ?? ?? ? ?? ?? ??? ????. ???? ??? ??, ?? ????, ?? ?? ? ????? ??? ?????. ?? ??,calculateArea ??? π? ???? ??? ??? ?? ??? ???? ?? ???? ?????.

??? ?? ????? ??? PHP8? ?? ?? ?? ??! PHP(Hypertext Preprocessor)? ? ??? ?? ???? ?? ?? ???? ?????. ??? ?? HTML? ?? ???? ??? ? ??? ?? ?? ?????? ?????. ?? ??? PHP8?? ?? ???? ? ??? ?? ??? ???? ????. ??? ??? ?? ????? ?? ? ?? 5?? ?? ?????. 1. JIT ????(Just-In-TimeCompile
