在阅读了c#的隐藏特性之后,我想知道Java的隐藏特性有哪些?
当前回答
我知道Java 6包括脚本支持,但我最近才发现jrunscript, 它可以交互式地解释和运行JavaScript(以及其他脚本语言,如Groovy),有点像Ruby中的Python shell或irb
其他回答
Self-bound泛型:
class SelfBounded<T extends SelfBounded<T>> {
}
http://www.artima.com/weblogs/viewpost.jsp?thread=136394
因为还没有人说过(我认为)我最喜欢的功能是自动装箱!
public class Example
{
public static void main(String[] Args)
{
int a = 5;
Integer b = a; // Box!
System.out.println("A : " + a);
System.out.println("B : " + b);
}
}
你可以在局部类的初始化块和方法中访问最终的局部变量和参数。考虑一下:
final String foo = "42";
new Thread() {
public void run() {
dowhatever(foo);
}
}.start();
有点像个了结,不是吗?
"const"是一个关键字,但你不能使用它。
int const = 1; // "not a statement"
const int i = 1; // "illegal start of expression"
我猜编译器的作者认为将来可能会用到它,他们最好保留它。
你可以在方法中声明一个类:
public Foo foo(String in) {
class FooFormat extends Format {
public Object parse(String s, ParsePosition pp) { // parse stuff }
}
return (Foo) new FooFormat().parse(in);
}
推荐文章
- 在流中使用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