Matt R
Matt R

Reputation: 10493

Calling Java from Scala: protected constructor

This compiles without error on Scala 2.8.0 final:

import javax.swing.tree.TreePath

object A extends Application {

  val path1 = new TreePath()
  val path2 = new TreePath(path1, "foo")

}

However, on execution I get:

java.lang.IllegalAccessError: tried to access method javax.swing.tree.TreePath.<init>()V from class A$
  at A$.<init>(A.scala:5)
  at A$.<clinit>(A.scala)
 at A.main(A.scala)

Is this a bug, feature, or a known limitation?

Upvotes: 2

Views: 971

Answers (1)

Rex Kerr
Rex Kerr

Reputation: 167881

This is a sort-of-bug, sort-of-feature. You certainly should get the access error (feature) because that's what protected is supposed to do. The compiler arguably ought to know enough about the context to be able to tell, however, and warn you instead of leaving it to runtime (bug, or at least candidate-for-enhancement).

Upvotes: 4

Related Questions