Solved

Passing arguments to a generic method

Posted on 2011-03-01
3
263 Views
Last Modified: 2012-05-11
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
Comment
Question by:CrazyOne
3 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 35004824
Set<T> t1 = new HashSet<T>();
Set<T> t2 = new HashSet<T>();

MySet.intersect(t1, t2);
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 250 total points
ID: 35004862
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
 
LVL 44

Author Closing Comment

by:CrazyOne
ID: 35040919
Thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now