Tips for writing concise and elegant Java

Share your tricks to make your Java code concise, still readable.

Based on Python, I suffer from “oh, it looks so verbose”, sometimes it’s hard to fit even 100-character long lines. I understand that Java is a little more verbose, and there is no way around it, but there must be little things that can save some bloated here and there ...

+5
source share
3 answers

Read the clean Bob Martin code. This is a book full of tips on this topic: writing well-organized, highly readable code, with Java as the example language.

+4
source

( if-then-else) .

String value = {condition} ? "Was true" : "Was false";
+1

:

  • : , , . ( ) Java7 elvis
  • : ! !
  • : Josh Bloch Effective Java. , (, "" " 7" ).
+1

All Articles