Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Passing arguments to a generic method

Posted on 2011-03-01
3
Medium Priority
?
272 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:
Gurvinder Pal Singh earned 1000 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 1000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

660 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