Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
That sucks! I prefer namespacing related objects and classes together. May end up with multiple source files, but the definitions are in one place. I don't much care for java in the first place though.
-
neeno31464yI fucking hate that, why can't I just group stuff that logically goes together without creating a bazillion folders? Thankfully I only use java for college assignments.
-
LLAMS36644yYou are allowed to put things in the same file if you want. It just affects how you import them elsewhere thats all.
You can only have one PUBLIC class per file, but you can have as many other classes as you want in there. But they will be package private at the very least. -
@yellow-dog what are you talking about, the code won't even compile unless each class/interface is in it's own file with it's own name(List class in List.java)
-
@LLAMS and that means every public class needs his own file, and most classes are public so you just said the same thing as me just in different words
-
LLAMS36644y@SoldierOfCode Except for the fact that I didnt, since you said that every type needs to be in its own separate file. I wouldnt actually say that because it is, in fact, not true.
-
@LLAMS But that's like arguing whether a soda costs 2$ or 1.9$
That's basically the same thing, it's still annoying even if it happens "only" 90% of the time... -
eeee31224yKotlin to the rescue!
Seriously, it runs on the JVM (and other runtimes) and fixes many of Java's legacy issues, including this one. It fully interoperates with Java, and Java with Kotlin. This means that you can start using it today!
Need declarations in one file? Please, go ahead!
Need declarations without classes? Suit yourself!
Or even the other way around: need multiple files to end up as one class? That's possible with Kotlin!
On top of that it's really a beautiful language and a joy to work with. Great tooling that helps you learn the language while you start naively writing Java as Kotlin. Idiomatic Kotlin is really powerful, because it's easy to read, understand and maintain, while it helps focus on solving your problems instead of trying to introduce boilerplate, which Java is so notorious for.
Related Rants
Java: each type is required being in a seperate file with the type's name, many of my projects have way to many files, half of them for really small interfaces or classes
rant
wk229
java