简体   繁体   中英

Understanding flow of object creation

I'm new to java and I wonder if there is simple way to know flow like the following of object creation, I'm using eclipse and when I write new ObjectInputStream and press CTRL + SPACE . I don't see any option that I can enter new BufferedInputStream (I have copied the code from example) and than to create new object for FileInputStream etc.

in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("emp.dat")));
List temp = (List)in.readObject();

I give that example since this is the first time that I saw this kind of creation new object flow and I want to use some best practice for the next times.

This is a classic example of using [Decorator Pattern][1] . You will wrap objects to add behavior.

This is very simple. This is equivalent to :

FileInputStream fis = new FileInputStream("emp.dat");
BufferedInputStream bis = new BufferedInputStream(fis)
ObjectInputStream in = new ObjectInputStream(bis);

As you are new to Java, you should check javadocs instead of checking it in Eclipse.

Check : FileInputStream , BufferedInputStream , ObjectInputStream

Ctrl + Space shows you options you have available at that point to get the options you might value if you created something you have to type new and then Ctrl + Space

BTW: ObjectInputStream and ObjectOutputStream are already buffered so adding more buffering isn't best practice IMHO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM