Interface name as a Type

Posted by user1889148 on Stack Overflow See other posts from Stack Overflow or by user1889148
Published on 2012-12-09T10:48:01Z Indexed on 2012/12/09 11:07 UTC
Read the original article Hit count: 216

Filed under:
|

I am trying to understand interfaces in Java and have this task to do which I am a stack with. It must be something easy, but I don't seem to see the solution. Interface contains a few methods, one of them should return true if all elements of this set are also in the set. I.e.

public interface ISet{
//some methods
   boolean isSubsetOf(ISet x);
}

Then the class:

public class myClass implements ISet{
       ArrayList<Integer> mySet;
       public myClass{
          mySet = new ArrayList<Integer>();
        }
       //some methods
       public boolean isSubsetOf(ISet x){
          //method body
    }
 }

What do I need to write in method body? How do I check that the instance of myClass is a subset of ISet collection? I was trying to cast, but it gives an error:

ArrayList<Integer> param = (ArrayList<Integer>)x;
    return param.containsAll(mySet);

© Stack Overflow or respective owner

Related posts about java

Related posts about interface