4 ms·
Been a while since I used java but is it still the case that your main function has to be inside a class which has to inherit, ultimately, from Object? I think
by sideshowb 6y ago
Been a while since I used java but is it still the case that your main function has to be inside a class which has to inherit, ultimately, from Object? I think that's what gp meant in implying that inheritance is not optional.
In practical terms of course a bit of boilerplate to declare a class where none was needed, doesn't matter a great deal.
- skinkestek 6y ago> but is it still the case that your main function has to be inside a class which has to inherit, ultimately, from Object? I think that's what gp meant in implying that inheritance is not optional. This is correct but not what GP wrote. What GP wrote is: > Unlike in Java, which offers practically nothing else [than inheritance] to organize a program, To point out why GP is wrong: - In Java you can organize files by packages - by purpose (different folders for test vs production code), - you can use composition to combine classes (in fact this is the recommended way these days) - etc I normally don't care about language wars but I think it is OK to point out when someone writes something that is clearly wrong.
- johnnycerberus 6y agoAlso, you can further organize your packages into Java modules (Java >=9). I don't know why people say that you can't use composition in Java or that it is unique to purely functional languages. You can achieve composition by using Streams, decorator, composite and chain of responsability patterns.