Questions about interfaces and objects | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Questions about interfaces and objects

So, I have two questions about programming in java: 1. how to know which objects you can combine with a certain interfaces (and vice versa)? I am referring to instances when I use an Interface as datatype. I am struggeling with this a lot. Often I just try random objects until my compiler does not complain (which is timeconsuming). The first place I looked was javadocs, but it's not in there, or I don't recognise it. (right now I'm looking for an object for the Set-interface, but I need to know where to find it for other interfaces to). 2. what happens when you use an interface as a datatype? honestly, I do not understand the benefits. The only reason I do it is because I have to for the assignments. Could somebody enlighten me?

4th Jan 2019, 2:32 PM
Jay Aberlour
Jay Aberlour - avatar
3 Answers
+ 2
Hmm.. I am sorry. I don't know the answer to your question. Java expert Danijel Ivanović may be able to help you 😉
4th Jan 2019, 3:36 PM
Gordon - avatar
Thanks @Gordon, but it doesn't really answer my question. Let me explain it another way: I need to store some data and I'm obligated to return a Set<String>. The code quite easy: Set<String> randomName = new blank; The problem is I can't figure out which objects I can put at blank. How do I know (or where can I find) which objects can be used with this interface?
4th Jan 2019, 3:22 PM
Jay Aberlour
Jay Aberlour - avatar