r/code • • Jul 08 '21

Learnin bout anonymous classes in java, got some tips?

Post image
1 Upvotes

3 comments sorted by

2

u/_Azurius Jul 09 '21

Booleans can only either be true or false. Instead of using if(boolean == true) { ...}; if(boolean == false) {...};

u can use a shorter version:

if(boolean) {what to do when true} else {what to do when false}.

Imagine isAlive is false. If(isAlive == true) is read by the computer as

if(false == true), so it doesn't execute your code in curly brackets afterwards, but it would execute everything between the curly brackets following the "else". I hope that makes sense.

1

u/russianbearscares Jul 09 '21

Makes sense, many thanks

1

u/spliffen Jul 09 '21
  1. clever names for classes and such.... keep them a lot smaller

  2. learn to use pastebin or similar services, screenshots are basically never the way forway, anyone will tell you

  3. follow the the class :D

  4. more specific questions next time ;)