Instantiate nested class in Scala when extending Java class

I have abstract java class which contains nested class declared as protected static:

public abstract class AbstractJavaClass {
  // contains nested class
  protected static class InnerClass {
  ...
  }
}

When I'm trying to instantiate it in Scala class extending AbstractJavaClass like I do in java (i.e. just referring name inside method new InnerClass):

class ScalaClass extends AbstractJavaClass {
   def method = new InnerClass()
}

I get error: type InnerClass is not a member of ScalaClass. What am I doing wrong? The same in java works fine.

Answers


Stumbled here: access java base class's static member in scala

It says

This isn't possible in Scala. Since Scala has no notation of static you can't
access protected static members of a parent class. This is a known limitation.

Though I couldn't resolve initial issue (when class is protected static), when I changed it to public static in definition of AbstractJavaClass I could use it this way:

class ScalaClass extends AbstractJavaClass {
  import AbstractJavaClass.InnerClass

  def method = new InnerClass
}

Using new InnerClass without import gives the same error.


Need Your Help

Learning EF Code First: What are the disadvantages compared to model first?

entity-framework-4.1 ef-code-first

I'm thinking about moving from EF model first to code first. The advantages look clear enough to me and it seems quite intuitve to use.

remember me cookies gets deleted symfony2

php symfony2 cookies

I am trying to configure remember me feature of symfony using their default mechanism as described here; but couldn't make it work.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.