Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java, is there a way to specify that an argument implements two interfaces

Tags:

java

I am tempted to do such kind of code, using jGraphT

/*
  interface DirectedGraph<V,E> { ...}
  interface WeightedGraph<V,E> { ...}
*/

public class SteinerTreeCalc  {

    public SteinerTreeCalc( < ??? implements DirectedGraph<V,E>, WeightedGraph<V,E> > graph )  {
     ......
    }


}

I want to create a constructor that ask for an object implementing two interfaces.

Update :

In my goal, there are already chosen classes for Vertex and Edges (V and E), but thanks a lot to people who come up with :

public class SteinerTreeCalc <V, E, T extends DirectedGraph<V, E> & WeightedGraph<V, E>>  
{ 
   ....
}
like image 341
jwinandy Avatar asked Sep 16 '10 08:09

jwinandy


1 Answers

Yes, it's possible:

public class SteinerTreeCalc<T extends DirectedGraph<V,E> & WeightedGraph<V,E>> {
  public SteinerTreeCalc(T graph) {
    ......
  }
}
like image 114
amorfis Avatar answered Sep 20 '22 05:09

amorfis