在阅读了c#的隐藏特性之后,我想知道Java的隐藏特性有哪些?
当前回答
也许最令人惊讶的隐藏特性是sun.misc.Unsafe类。
http://www.docjar.com/html/api/ClassLib/Common/sun/misc/Unsafe.java.html
你可以;
Create an object without calling a constructor. Throw any exception even Exception without worrying about throws clauses on methods. (There are other way to do this I know) Get/set randomly accessed fields in an object without using reflection. allocate/free/copy/resize a block of memory which can be long (64-bit) in size. Obtain the location of fields in an object or static fields in a class. independently lock and unlock an object lock. (like synchronize without a block) define a class from provided byte codes. Rather than the classloader determining what the byte code should be. (You can do this with reflection as well)
BTW:不正确地使用这个类会杀死JVM。我不知道哪个jvm支持这个类,所以它不能移植。
其他回答
我喜欢
Javadoc的taglet和doclet使我们能够自定义Javadoc输出。 JDK工具:jstat, jstack等。
我差点忘了这个小宝贝。在任何正在运行的java进程上尝试这个:
jmap -histo:活动PID
您将得到给定VM中活动堆对象的直方图。作为一种快速计算某些类型的内存泄漏的宝贵方法。我使用的另一种技术是创建和使用所有集合类的有大小限制的子类。这将导致容易识别的失控集合出现快速故障。
逗号和数组。字符串s[] = { “123”, “234”, };
对于我面试的大多数Java开发人员来说,标记为块的职位是非常令人惊讶的。这里有一个例子:
// code goes here
getmeout:{
for (int i = 0; i < N; ++i) {
for (int j = i; j < N; ++j) {
for (int k = j; k < N; ++k) {
//do something here
break getmeout;
}
}
}
}
谁说goto在java中只是一个关键字?:)
你可以在局部类的初始化块和方法中访问最终的局部变量和参数。考虑一下:
final String foo = "42";
new Thread() {
public void run() {
dowhatever(foo);
}
}.start();
有点像个了结,不是吗?
推荐文章
- 在流中使用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