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
Solved

Passing arguments to a generic method

Posted on 2011-03-01
3
266 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 45
How to convert from xls to xlsx using java 7 54
CSV file parsing thru Java 13 34
Java syntax, or is it Selenium 6 30
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

790 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