DEV Community

hinst
hinst

Posted on

Top 5 Java troll moments

  1. Memory limit is not a real memory limit 🤔
    • I can define heap memory limit for the JVM... But the actual memory usage can end up being 10% higher, or 20%, or even 50% higher, because native memory allocations are not counted as heap memory
    • My app will use all available memory inside the container and crash, even though I thought I set a limit... What?
    • At this point, why even have a memory limit at all?
  2. Reserved words that do nothing 🅰️
    • const is a reserved keyword, but I cannot define a constant value with it
    • _ underscore is also a reserved keyword, but it cannot be used until Java 25. It took 10+ years from keyword introduction to actual implementation. No way... Better later than never?
  3. Character to number implicit casting 🔟
    • It is possible to create string builder from character: new StringBuilder('a'). But 'a' will be treated as integer 97. What the heck...
  4. ForkJoinPool.commonPool() 📊
    • The number of available threads is limited to the number of CPU threads
    • If some tasks spawn other tasks, then I will run out of threads and enter a deadlock... Or not, if I am lucky enough to run on a multicore CPU with enough cores
    • No error message, only infinite waiting
  5. Check if two objects are equal 🍏
    • Compare two strings using == operator, a beginner's mistake
    • Or compare two objects using a.equals(b), only to find out that the objects belong to different classes, and cannot be equal ever
    • These errors can only be caught effectively with a good linter. Compiler will say nothing about those errors
    • Bonus headache if one of the objects is null, calling null.equals()

Top comments (0)