2024-04-20 09:00:01

Java的隐藏特性

在阅读了c#的隐藏特性之后,我想知道Java的隐藏特性有哪些?


当前回答

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).

其他回答

Self-bound泛型:

class SelfBounded<T extends SelfBounded<T>> {
}

http://www.artima.com/weblogs/viewpost.jsp?thread=136394

一些控制流的技巧,最后围绕一个return语句:

int getCount() { 
  try { return 1; }
  finally { System.out.println("Bye!"); }
}

确定赋值规则将检查最终变量总是通过简单的控制流分析进行赋值:

final int foo;
if(...)
  foo = 1;
else
  throw new Exception();
foo+1;

一种可以为基于Java控制台的应用程序显示启动画面的功能。

使用带有-splash选项的命令行工具java或javaw

eg:

java -splash:C:\myfolder\myimage.png -classpath myjarfile.jar com.my.package.MyClass

C:\myfolder\myimage.png的内容将显示在你的屏幕中央,每当你执行类"com.my.package.MyClass"

泛型方法的类型参数可以像这样显式指定:

Collections.<String,Integer>emptyMap()

当我第一次注意到三元运算符等于一个简单的if-then-else语句时,我很惊讶:

minVal = (a < b) ? a : b;