preface

When you read the source code, see those inherited to implement various classes and interfaces, is not already know his father (parent class), his grandfather (parent class) who is, only know his ancestor (Object class)? After all, the relationship between classes is too ambiguous to say anything other than “What a mess.”

It doesn’t matter, Idea has a super powerful and practical thing, which can make you immediately understand the relationship between them and easily solve the relationship between them. After all, no one wants to be a father. “Why do I suddenly have an inner class? If you look at the green interface, he doesn’t know how many kids he has

The theme of the style is really my appetite (geek feeling), Idea theme style is more beautiful


All articles are synchronized with Github–Java-Notes, to learn about JVM(basic to complete), HashMap source analysis, Spring related, concurrent, sword offer problem solving (Java version), you can click a star. You can see my Github homepage, which is updated every day. (Since I started to work, I have been writing at 12 o ‘clock in the evening and getting up at 6 o ‘clock in the morning. My daily motivation is to see the number of stars rising.)

I invite you to complete the REPO with me


The meaning of the line

Solid blue line –> Inheritance

Green dotted line –> implementation

Red implementation –> Inner class

Let’s take ReentrantLock as an example

Forgive the color

We see that it implements both Lock and Serializable interfaces, so the class diagram shows that the green dotted line interface does not know how many children it has. Pardon the color

red

As you can see, Sync is an abstract class inside the ReentrantLock class, which is represented by the red line in the class diagram

Don’t believe we’ll look at another class AbstractQueuedSynchronizer

blue

Sync inherited from AbstractQueuedSynchronizer, and all of the classes (in addition to the Object), is inherited from Object, so all the blue line will point to the Object of a class

How do we do that?

Select the class, right click

Two modes

  • The first one is the one I showed you at the beginning, which opens in a separate window
  • The second one will pop up a window directly next to the class, showing the relationship

We mainly take the first example to show, how to show so many categories step by step, find out his so many fathers, uncles, grandpa, and ancestors

Find out who his hidden relatives are

As soon as we go in, it’s not like WHAT I started with, all sorts of confusing fathers and uncles, because it just shows the immediate parent class and the interface that it implements

Look for his father first

ReentrantLock is a rich second generation, he has no grandfather, ancestors, only a father. Because it inherits no classes other than Object

Find his adopted son (inner class, not inherited from him)

Filter, screen

Look for Sync’s parent class twice

Enter the source code

This can jump directly into the source code

Adding other classes

Sometimes you feel that the class is not what you want, and you need to cross-reference the class by looking for an uncle (same grandfather, but no direct inheritance) or a sibling (same father).

You can just right click on this

Then enter the classes you want to add, such as Thread

If the two are not related (if the classes are related, after all, they inherit from Object, but if the parent class is not loaded, it is not related), then there is no connection. For example, we delete the Object class

The last

With something like this, I think you can read the source code or do anything else without getting confused about the relationship between classes and classes /(interfaces)

I wish you all a happy reading of the source code, interpretation of the relationship between them