Solved

Passing arguments to a generic method

Posted on 2011-03-01
3
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

635 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