在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
Java泛型 都是WTF:
List<String> ls = new ArrayList<String>(); //1
List<Object> lo = ls; //2
2:是非法的(??)这是令人费解的,但你必须想想接下来会发生什么:
lo.add(new Object());
String s = ls.get(0);
我们将对象赋值给字符串引用,哦不!就像这样,他们周围有很多陷阱。
其他回答
在Perl中,你可以做到:
my $test = "Hello World";
substr($test, 0, 5) = "Goodbye";
print $test;
这在其他语言中可行吗?
C# has a feature called "extension methods", which are roughly analogous to Ruby mix-ins - Essentially, you can add a method to any pre-existing class definition (for instance, you oould add "reverse()" to String if you were so inclined). That alone is fine- The "Weird" part is that you can add these extension methods, with a method body and everything, to an interface. On the one hand, this can be handy as a way to add a single method to a whole swath of classes which aren't part of the same inheritance tree. On the other, you're adding fleshed out methods to interfaces, essentially breaking the very definition of an interface.
任何东西都会自动将任何类名和成员名复数或单数。
例如,Linq-to-Sql
在JavaScript中:
alert(111111111111111111111) // alerts 111111111111111110000
这对我在JSON中来回传递的一些64位键非常不利。
在Visual Basic 7及以上版本中,我发现实现了短路逻辑求值以保持与遗留的Visual Basic <=6代码的兼容性,有点WTF:
而且 (MSDN) OrElse (MSDN)