2

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.

4
  • 1
    I think what might help find an answer is that Scala specfically cannot import an inner Java class. Do either of these references help? stackoverflow.com/questions/42322033/… stackoverflow.com/questions/52132456/… Commented Feb 10, 2020 at 15:59
  • 1
    I think the usage should be something like val gl = new javax.swing.GroupLayout(new Container()) and then gl.createParallelGroup() or gl.createSequentialGroup() Commented Feb 10, 2020 at 16:00
  • Found this: users.scala-lang.org/t/… Commented Feb 10, 2020 at 16:03
  • But I'd like to generate a generic method that takes as a parameter a Group, that could be either a ParallelGroup or a SequientialGroup. Commented Feb 10, 2020 at 16:04

1 Answer 1

4

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) = ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.