在阅读了c#的隐藏特性之后,我想知道Java的隐藏特性有哪些?
当前回答
他们花了足够长的时间来增加支持,
系统托盘
其他回答
最终初始化可以推迟。
它确保即使使用复杂的逻辑流也始终设置返回值。很容易错过一个case并意外返回null。它并不是不可能返回null,只是很明显它是故意的:
public Object getElementAt(int index) {
final Object element;
if (index == 0) {
element = "Result 1";
} else if (index == 1) {
element = "Result 2";
} else {
element = "Result 3";
}
return element;
}
语言级assert关键字。
The power you can have over the garbage collector and how it manages object collection is very powerful, especially for long-running and time-sensitive applications. It starts with weak, soft, and phantom references in the java.lang.ref package. Take a look at those, especially for building caches (there is a java.util.WeakHashMap already). Now dig a little deeper into the ReferenceQueue and you'll start having even more control. Finally grab the docs on the garbage collector itself and you'll be able to control how often it runs, sizes of different collection areas, and the types of algorithms used (for Java 5 see http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html).
我真的很喜欢从Java 1.6重写的线程API。可调用对象很棒。它们基本上是带有返回值的线程。
您选择的编码中的属性文件如何?过去,当你加载你的属性,你提供了一个InputStream和load()方法解码为ISO-8859-1。你实际上可以用其他编码来存储文件,但你必须在加载后使用像这样令人作呕的黑客来正确解码数据:
String realProp = new String(prop.getBytes("ISO-8859-1"), "UTF-8");
但是,从JDK 1.6开始,有一个load()方法接受Reader而不是InputStream,这意味着您可以从一开始就使用正确的编码(还有一个store()方法接受Writer)。对我来说,这似乎是一件相当大的事情,但它似乎是悄无声息地潜入JDK的。我几周前才偶然发现它,快速搜索谷歌,只发现了一个提及。
推荐文章
- 在Selenium中等待页面加载
- Maven父pom vs模块pom
- 将JSON数据转换为Java对象
- Java的隐藏特性
- 使用Java 8的可选Stream::flatMap
- 使用管道字符("|")分割字符串
- 在IntelliJ中找不到Maven插件
- Java List.add() UnsupportedOperationException
- 连接两个字节数组的简单方法
- 为什么Mockito不模拟静态方法?
- Volatile boolean vs AtomicBoolean
- 在一个类中使用相同的方法实现两个接口。覆盖了哪个接口方法?
- 线程的上下文类装入器和普通类装入器之间的区别
- 如何在Java中正确地比较两个整数?
- 在Java中获取“unixtime”