在阅读了c#的隐藏特性之后,我想知道Java的隐藏特性有哪些?
当前回答
它并不是完全隐藏的,但反射是非常有用和强大的。使用简单的class . forname("…"). newinstance()是很好的,其中类类型是可配置的。编写这种工厂实现很容易。
其他回答
我个人很晚才发现java.lang.Void——结合泛型提高了代码的可读性,例如Callable<Void>
几个月前当我第一次发现它时,双括号初始化让我感到惊讶,以前从未听说过它。
作为存储每个线程状态的一种方式,ThreadLocals通常并不广为人知。
由于JDK 1.5 Java已经有了非常好的实现和健壮的并发工具,而不仅仅是锁,它们存在于Java .util.concurrent中,一个特别有趣的例子是Java .util.concurrent.atomic子包,它包含线程安全的原语,实现比较和交换操作,并可以映射到这些操作的实际本机硬件支持版本。
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.util.Arrays中的asList方法允许变量参数、泛型方法和自动装箱的良好组合:
List<Integer> ints = Arrays.asList(1,2,3);
字符串参数化类工厂。
Class.forName( className ).newInstance();
从部署jar文件中加载资源(属性文件,xml, xslt,图像等)。
this.getClass().getClassLoader().getResourceAsStream( ... ) ;
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder
- 将JSON字符串转换为HashMap