Home > Java > javaTutorial > body text

Common mistakes and precautions when using Java internal classes

WBOY
Release: 2023-04-21 09:16:15
forward
914 people have browsed it

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);
            }
        };
    }
}
Copy after login

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();
    }
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!