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

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


当前回答

在JavaScript中,下面的构造

return
{
    id : 1234,
    title : 'Tony the Pony'
};

返回undefined是一个语法错误,因为在返回后的换行上偷偷地插入了分号。以下工作正如你所期望的那样:

return {
    id : 1234,
    title : 'Tony the Pony'
};

更糟糕的是,这个也可以(至少在Chrome中):

return /*
*/{
    id : 1234,
    title : 'Tony the Pony'
};

下面是同一个问题的一个变种,它不会产生语法错误,只是无声地失败了:

return
    2 + 2;

其他回答

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

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

Java泛型 都是WTF:

List<String> ls = new ArrayList<String>(); //1
List<Object> lo = ls; //2

2:是非法的(??)这是令人费解的,但你必须想想接下来会发生什么:

lo.add(new Object());
String s = ls.get(0);

我们将对象赋值给字符串引用,哦不!就像这样,他们周围有很多陷阱。

通知7。一个有效程序的例子:

    Chomsky is a room. 
    A thought is a kind of thing. 
    Color is a kind of value. 
    The colors are red, green and blue. 
    A thought has a color. It is usually Green. 
    A thought can be colorful or colorless. It is usually colorless. 
    An idea is a thought in Chomsky with description "Colorless green ideas sleep furiously." 
    A manner is a kind of thing. 
    Furiously is a manner. 
    Sleeping relates one thought to one manner. 
    The verb to sleep (he sleeps, they sleep, he slept, it is slept, he is sleeping) implies the sleeping relation. 
    Colorless green ideas sleep furiously. 

像图灵机模拟器这样的其他愚蠢的东西可以找到。

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

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

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

很久以前,我曾经用BUT子句构建过一种语言。