java - Intersection type with type definition -


i have java interface uses intersection type this:

public interface javaintersection{     public <e extends jcomponent & runnable> void foo(e arg); } 

and i'm trying create scala class implements interface. wrote following:

class scalaintersection extends javaintersection{   override def foo[e <: jcomponent runnable](arg:e):unit = ??? } 

this works but, in full program i'm writing, type gets used in multiple places. having include full type each time pretty tedious. modified class this:

class scalaintersection extends javaintersection{   type runnablecomponent <: jcomponent runnable   override def foo(arg:runnablecomponent):unit = ??? } 

with change program no longer compiles, following errors:

error: class scalaintersection needs abstract, since method foo in trait javaintersection of type [e <: javax.swing.jcomponent runnable](arg: e)unit not defined

error: method foo overrides nothing.
[info] note: super classes of class scalaintersection contain following, non final members named foo:
[info] def foo[e <: javax.swing.jcomponent runnable](arg: e): unit

is there way in scala implement interface method takes class implementing interface, without needing write entire type on every method?

this error arises because you've removed type parameter, , signature of method trying implement. compiler sees haven't implemented original method in question:

error: class scalaintersection needs abstract, since method foo in trait javaintersection of type [e <: javax.swing.jcomponent runnable](arg: e)unit not defined

you cannot use type alias remove both long type name and type parameter of method of type upper-bound (at least not syntax). instead, make type alias intersection type. don't see way lose type parameter completely, method implementing requires it.

class scalaintersection extends javaintersection {   type runnablecomponent = jcomponent runnable   override def foo[e <: runnablecomponent](arg: e): unit = ??? } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -