在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

在Java中(实际上,我最近在不同的SO帖子上写过这个):

    int x = 1 + + + + + + + + + + + + + 1;
    System.out.println(x);

其他回答

在c#中,为什么这是不合法的?

public class MyClass<T>
    where T: Enum
{

}

能够在Enum上添加扩展方法以及Func<T>是非常酷的,其中T将是您正在扩展的Enum,以便您可以对该Enum进行类型推断。

回复评论:是的,你可以扩展一个实际的枚举,但这里有区别:

你可以这样做:

public static void DoSomethingWithEnum(this Enum e)
{
   //do whatever
}

但是如果你想用你的方法获取一个Func,它将是你的enum的相同类型:

public static void DoSomethingWithEnum<T>(this T e, Func<T,bool> func )
   where T: Enum
{
   //do whatever
}

这样,你就可以像这样调用你的方法:

DayOfWeek today = DayOfWeek.Monday;
today.DoSomethingWithEnum(e => e != DayOfWeek.Sunday);

或者类似的东西。你懂的…这是不可能的,我也不知道为什么……

在JavaScript中:

2 == [2]

//更陌生 2 == [[[2]]]

//和彻头彻尾的坚果 Var a = {"abc": 1}; A [[[["abc"]]]] === A ["abc"];//这也是正确的

幸运的是,stackoverflow.com网站上善良的人们向我解释了这一切:http:/stackoverflow.com/questions/1724255/why-does-2-2-in-javascript

APL(除了ALL),在一行中编写任何程序的能力。

例:在APL中,康威的生命游戏一行:

替代文本 http://catpad.net/michael/APLLife.gif

如果这句台词都不是WTF,那什么都不是!

这是一个视频

在Ruby中,你可以用heredocs做一些奇怪的事情。考虑:

a = <<ONE
This is one. #{<<TWO}
This is two. #{<<THREE}
This is three.
THREE
TWO
ONE

p a # => "This is one. This is two. This is three.\n\n\n"

这是我最喜欢的一个,你可以在Java中不使用main()来执行println。

这将编译和运行,给出println,但也有一个异常(java.lang。NoSuchMethodError:主要)

class Test {
    static {
        System.out.println("I'm printing in Java without main()");
    }
}