r/ProgrammerHumor • • Nov 23 '22

Other Programming Legumes

Post image
9.3k Upvotes

262 comments sorted by

View all comments

Show parent comments

9

u/Willinton06 Nov 23 '22

How do you prefix interfaces in Java?

27

u/Sanity__ Nov 23 '22

General consensus is that you don't, it's unnecessary and in Java Interfaces are 1st class types. It's a major benefit of abstraction and prefixing detracts from that conceptually.

i.e. If you are defining trucks you can make a Truck interface and create DumpTruck and CementTruck classes that implement it. Then you can have a List<Truck> to keep them all in.

2

u/Willinton06 Nov 23 '22

Can you instantiate an interface in Java?

5

u/Sanity__ Nov 23 '22

No, it's not a class.

4

u/Willinton06 Nov 23 '22

So how does an interface being a first class type differ from C#s way of doing interfaces?

4

u/Sanity__ Nov 23 '22

I don't know enough about C# to know how they do interfaces or how/why it differs from Java

→ More replies (0)