10

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

Comments
  • 9
    Ehm.

    Eh.

    That's called sanity?
  • 5
    Makes sense to me...
  • 5
    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.
  • 1
    I 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.
  • 0
    They arent btw, its just convention
  • 0
    You 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.
  • 0
    @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)
  • 0
    @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
  • 0
    That's supposed to be like that.
  • 0
    @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.
  • 0
    @SoldierOfCode java has inner classes and even anonymous classes
  • 0
    @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...
  • 0
    @yellow-dog well yeah, but most classes are public
  • 0
    ???????????what
  • 0
    Welcome to OOP and non super shitty unbrearable coding I guess ?
  • 0
    Kotlin 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.
Add Comment