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

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


当前回答

Java;使所有对象实例都是互斥对象。

其他回答

在Java中,字符串如何处理==操作符取决于它是如何构造的,这存在一些不一致性。

String a = "Hello";
String b = "Hello";
System.out.println(a == b ); // prints true.
String c = new String("Hello");
String d = new String("Hello"); 
System.out.println(c == d ); // prints false

下面是一个关于python的例子:

>>> print 07
7
>>> print 08
  File "<stdin>", line 1
    print 08
           ^
SyntaxError: invalid token

那不是很美吗?

尤其当你想到人类是如何写日期的时候,你会觉得很不周到,这有以下影响:

datetime.date(2010,02,07) # ok
datetime.date(2010,02,08) # error!

(原因是0x被解释为八进制,所以打印010打印8!)

在Java中,如果x的值为NaN,则x == x返回false, x != x返回true。

英语中的虚拟语气。

等等,你是说编程语言吗?然后在C中使用(宏)绕过宏()的预处理器#定义。例如,如果有人使用#define free(…),(free)(…)将与free(…)不同。

c++(或Java)中没有封装的事实。任何对象都可以违反任何其他对象的封装,破坏它的私有数据,只要它是相同的类型。例如:

#include <iostream>
using namespace std;

class X
{
  public:
    // Construct by passing internal value
    X (int i) : i (i) {}

    // This breaks encapsulation
    void violate (X & other)
    {
        other.i += i;
    }

    int get () { return i; }

  private:
    int i;
};

int main (int ac, char * av[])
{
    X a(1), b(2), c(3);

    a.violate (c);
    b.violate (c);
    cout << c.get() << endl;    // "6"
}