Hacker News new | past | comments | ask | show | jobs | submit login

> You can literally write code that will compile in both.

An example, please.




int fibonacci(int n) {

    if (n <= 0) return 0;

    if (n == 1) return 1;

    int a = 0, b = 1, temp;
    for (int i = 2; i <= n; i++) {
        temp = a + b;
        a = b;
        b = temp;
    }
    return b;
}

...if only the return type was "Crow" then you could .eat() that...


That will not compile with javac, as it is not a method of a class.


That code will it just needs to be in the proper context. No the same file will not compile, even if only because javac needs files to end with .java .


Java has "unnamed classes" now which makes this work.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: