0
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?
3 Réponses
+ 5
GetInterfaces()?
https://www.tutorialspoint.com/java/lang/class_getinterfaces.htm
Tried to code something like this, but failed 😗
https://code.sololearn.com/c0iYQv5K9TyA/?ref=app
https://code.sololearn.com/cV9OZWRAyHIT/?ref=app
+ 2
Hmm.. I am sorry. I don't know the answer to your question. Java expert Danijel Ivanović may be able to help you 😉
0
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?