Home >Java >javaTutorial >Common mistakes and precautions when using Java internal classes
1. Handling of memory leaks
has nothing to do with class member methods and member variable methods. It is best to define them as static.
public class Outer{ public static List<String> getList(String item) { return new ArrayList<String>() { { add(item); } }; } }
2. Suitable for implementation classes that only implement one interface
Try not to use Thread directly. Here, if using only Java8, it is recommended to use lambda instead for such an application.
new Thread(new Runnable() { @Override public void run() { System.out.println("test"); } } ).start(); }
The above is the detailed content of Common mistakes and precautions when using Java internal classes. For more information, please follow other related articles on the PHP Chinese website!