david.perez
david.perez

Reputation: 7012

Scala can't import a class that Java can

Why I can do this in Java:

import javax.swing.GroupLayout.Group;

but if I do the same in Scala (by using Ammonite), I get this:

value Group is not a member of object javax.swing.GroupLayout possible cause: maybe a semicolon is missing before `value Group'? import javax.swing.GroupLayout.Group

Is it due to the fact that Group is a public class derived from a private class called Spring?.

I can import neither SequentialGroup nor ParallelGroup.

Is it a bug in Scala? I'm using Java 11 and Scala 2.12.10.

Scala 2.13.1 also fails. :-(

I need the import, for defining a generic method that can have a Group parameter, that could be either a ParallelGroup or a SequentialGroup.

Upvotes: 2

Views: 291

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170723

I'd like to generate a generic method that takes as a parameter a Group, that could be either a ParallelGroup or a SequientialGroup

That would be a type projection

def method(group: GroupLayout#Group) = ...

or if you also have the layout the group belongs to,

def method(layout: GroupLayout)(group: layout.Group) = ...

or

val layout: GroupLayout = ...
def method(group: layout.Group) = ...

Upvotes: 4

Related Questions