In this chapter we will briefly introduce the single inheritance and the container.
1. Single Root inheritance
Concept:
A single inheritance, which means that all classes inherit from the same inheritance pattern as the base class
Advantages:
(1) All objects have a common interface, which in the final analysis is the same basic type.
Package Com.ray.ch01;public class Jack extends Object {}
In fact, when we create a new class, it inherits the root class of object by default, so when we create a new class, we can also write it like this. Let's test it down here.
Package Com.ray.ch01;public class Jack {public static void main (string[] args) {Jack Jack = new Jack (); System.out.println (Jack instanceof Object);}}
Output:
True
(2) A single inheritance structure ensures that all objects have certain functions.
As you can see, the Jack object is equipped with all the methods in object.
(3) A single inheritance structure makes it much easier to implement the garbage collector.
Because it is a single inheritance, the algorithm for calculating the use of objects becomes much easier.
2. Collection
(1) Why do I need a collection?
Because there is no way to predict how many objects need to be stored during normal programming, if you use a simple array that does not meet such requirements, there is a collection that can be self-expandable.
(2) Type
Storage sequence list, associative array map, single storage set, etc.
(3) Select
Because different collections meet different needs, they must be chosen according to the business. For example:
When most of you just need to read, then choose ArrayList more appropriate, it is characterized by easy to read, insert difficult
When you are inserting data in most cases, you should choose LinkedList, which is suitable for random storage, but low random read performance
2.1. Generics
Since a collection is just a storage object, there can be a variety of problems and exceptions for a downward transformation that often occurs in a business scenario, so Java introduces a generic concept that controls each collection just to put specific objects.
Summary: This section provides a simple introduction to single inheritance and collections, and the collections and generics are expanded in detail in later chapters.
This chapter is here, thank you.
-----------------------------------
Directory
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Understanding java-1.7 Single root inheritance and collection from the beginning