| |

VerySource

 Forgot password?
 Register
Search
Author: liux83

The toString() problem is handled in the magic interface! !

[Copy link]

0

Threads

23

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-9-30 13:45:01
| Show all posts
>>This phenomenon is indeed very interesting. The above few people seem to have not noticed a problem, that is, the research object here is like an "interface".
>>Rather than "class", and the interface seems to not inherit the Object class theoretically

EmptyInterface e = new SomeImplemention();
String s = e.toString();//e Since it is an instance of an interface, it proves that it is an object. It must be Object that can inherit the interface. The compiler and you and I know this. Sorry.
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-9-30 18:15:01
| Show all posts
//e is an instance of the interface
The interface cannot have an instance, the interface only provides a series of method interfaces, and they are all empty for the polypeptide mechanism
Reply

Use magic Report

0

Threads

23

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-9-30 19:00:01
| Show all posts
//e is an instance of the interface
>>The interface cannot have an instance, the interface only provides a series of method interfaces, and they are all empty for the polypeptide mechanism
Of course, interfaces can have instances (instance, nouns), and abstract classes can also have instances, but they cannot be instantiated directly. An object that implements an interface is an instance of this interface.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-10-1 10:30:01
| Show all posts
This is just an overwrite of toString() in the Object class, not the content in test,
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list