This page is no longer maintained — Please continue to the home page at www.scala-lang.org

constructor not accessible

1 reply
Jan Kriesten
Joined: 2009-01-13,
User offline. Last seen 2 years 39 weeks ago.

Hi,

I have some weird behavior with the scala compiler making a difference between
typed java public and protected constructors.

Given the following Java class:

----------
package jfiles;
public abstract class DataView { protected DataView(T id) { } }
----------

When trying to extend this class in Scala with

----------
package sfiles
import jfiles.DataView
class myDataView extends DataView( "String" )
----------

I get the following error:

sfiles/myDataView.scala:3: error: constructor DataView cannot be accessed in
package sfiles
class myDataView extends DataView( "String" )

If the Java class has a public constructor, this works without a problem!

To get the above Scala source compiling with the protected version, I need to
give a hint on the type:

----------
package sfiles
import jfiles.DataView
class myDataView extends DataView[String]( "String" )
----------

Can someone give me a hint why? At least the error message is somewhat
irritating. Or should I call this a bug and file it?

Best regards, --- Jan.

Ricky Clarkson
Joined: 2008-12-19,
User offline. Last seen 3 years 2 weeks ago.
Re: constructor not accessible
I'd file a bug.

2009/3/27 Jan Kriesten <kriesten@mail.footprint.de>

Hi,

I have some weird behavior with the scala compiler making a difference between
typed java public and protected constructors.

Given the following Java class:

----------
package jfiles;
public abstract class DataView<T> { protected DataView(T id) { } }
----------

When trying to extend this class in Scala with

----------
package sfiles
import jfiles.DataView
class myDataView extends DataView( "String" )
----------

I get the following error:

sfiles/myDataView.scala:3: error: constructor DataView cannot be accessed in
package sfiles
class myDataView extends DataView( "String" )

If the Java class has a public constructor, this works without a problem!

To get the above Scala source compiling with the protected version, I need to
give a hint on the type:

----------
package sfiles
import jfiles.DataView
class myDataView extends DataView[String]( "String" )
----------


Can someone give me a hint why? At least the error message is somewhat
irritating. Or should I call this a bug and file it?

Best regards, --- Jan.



Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland