- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Can't access protected static inner classes of extended classes
Thu, 2009-03-19, 16:53
This looks like a bug to me, since it works in Java.
Given a Java class defined like this:
package com.example;
public abstract class Test{
protected static class Inner{}
protected abstract Inner getInner();
}
It is not possible to implement this class in Scala from another package:
Welcome to Scala version 2.7.3.final (OpenJDK Server VM, Java 1.6.0_0).
scala> import com.example.Test
import com.example.Test
scala> class Implementor extends Test{
| import Test.Inner
| def getInner:Inner = null
| }
:7: error: class Inner cannot be accessed in object com.example.Test
def getInner:Inner = null
^
Aside from that Inner is not in scope as you would expect it to be:
scala> class Implementor extends Test{
| def getInner:Inner = null
| }
:6: error: not found: type Inner
def getInner:Inner = null
^
I'm wondering why no one stumbled over this case yet. Am I missing
something? Any workarounds?
Johannes
-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
Thu, 2009-03-19, 17:27
#2
Re: Can't access protected static inner classes of extended cl
Filed as #1806: https://lampsvn.epfl.ch/trac/scala/ticket/1806
Johannes
-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
On Thu, Mar 19, 2009 at 5:11 PM, Ricky Clarkson
wrote:
> It's even worse in trunk. Just got a crash. :)
>
> I'd report a bug.
>
> 2009/3/19 Johannes Rudolph :
>> This looks like a bug to me, since it works in Java.
>>
>> Given a Java class defined like this:
>>
>> package com.example;
>>
>> public abstract class Test{
>> protected static class Inner{}
>> protected abstract Inner getInner();
>> }
>>
>> It is not possible to implement this class in Scala from another package:
>>
>> Welcome to Scala version 2.7.3.final (OpenJDK Server VM, Java 1.6.0_0).
>> scala> import com.example.Test
>> import com.example.Test
>>
>> scala> class Implementor extends Test{
>> | import Test.Inner
>> | def getInner:Inner = null
>> | }
>> :7: error: class Inner cannot be accessed in object com.example.Test
>> def getInner:Inner = null
>> ^
>>
>> Aside from that Inner is not in scope as you would expect it to be:
>>
>> scala> class Implementor extends Test{
>> | def getInner:Inner = null
>> | }
>> :6: error: not found: type Inner
>> def getInner:Inner = null
>> ^
>>
>> I'm wondering why no one stumbled over this case yet. Am I missing
>> something? Any workarounds?
>>
>> Johannes
>>
>> -----------------------------------------------
>> Johannes Rudolph
>> http://virtual-void.net
>>
>
It's even worse in trunk. Just got a crash. :)
I'd report a bug.
2009/3/19 Johannes Rudolph :
> This looks like a bug to me, since it works in Java.
>
> Given a Java class defined like this:
>
> package com.example;
>
> public abstract class Test{
> protected static class Inner{}
> protected abstract Inner getInner();
> }
>
> It is not possible to implement this class in Scala from another package:
>
> Welcome to Scala version 2.7.3.final (OpenJDK Server VM, Java 1.6.0_0).
> scala> import com.example.Test
> import com.example.Test
>
> scala> class Implementor extends Test{
> | import Test.Inner
> | def getInner:Inner = null
> | }
> :7: error: class Inner cannot be accessed in object com.example.Test
> def getInner:Inner = null
> ^
>
> Aside from that Inner is not in scope as you would expect it to be:
>
> scala> class Implementor extends Test{
> | def getInner:Inner = null
> | }
> :6: error: not found: type Inner
> def getInner:Inner = null
> ^
>
> I'm wondering why no one stumbled over this case yet. Am I missing
> something? Any workarounds?
>
> Johannes
>
> -----------------------------------------------
> Johannes Rudolph
> http://virtual-void.net
>