Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Passing arguments to a generic method

Ok I have a Class that is going to be used as a template. How do i pass the arguments in the "intersect" method from another Class. Lets presume in this case <T> is of the String type.

import java.util.*;
public class MySet<T> implements Set<T>
{
      private ArrayList<T> set;
      
      public MySet()
      {
         set = new ArrayList<T>();
      }

        public static <T> Set<T> intersect(Set<T> first, Set<T> second )
      {
            //some code here
        }
}  
0
CrazyOne
Asked:
CrazyOne
2 Solutions
 
Gurvinder Pal SinghCommented:
Set<T> t1 = new HashSet<T>();
Set<T> t2 = new HashSet<T>();

MySet.intersect(t1, t2);
0
 
for_yanCommented:
import java.util.Set;


public class MySetCall {
    
   static  Set<String> s1;
    static Set<String> s2;
    
   static Set<String> s3 =  MySet.intersect(s1,s2);
    
    
    
}

Open in new window

0
 
CrazyOneAuthor Commented:
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now