Passing arguments to a generic method

Posted on 2011-03-01
Medium Priority
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
Question by:CrazyOne
LVL 40

Accepted Solution

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);
LVL 47

Assisted Solution

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

LVL 44

Author Closing Comment

ID: 35040919

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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 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:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

600 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