Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:25:23+00:00 2026-05-23T10:25:23+00:00

I am writing a Scala class to inherit from a Java class, and I

  • 0

I am writing a Scala class to inherit from a Java class, and I must override a method that takes a protected Java inner class as a parameter. The Java dependency comes as a jar without source code.

I have the exact same setup as found in https://issues.scala-lang.org/browse/SI-3120 except that I do not have the Java source code available, so scalac only knows about the Java dependency by looking at the byte code (in jar or class files).

This is basically what I’m trying to do:

// javapkg/JavaSuperClass.java
package javapkg;
public class JavaSuperClass {
    protected class JavaInnerClass {
    }
    public void method(JavaInnerClass javaInnerclass) {
        System.out.println("hello");
    }
}

// scalapkg/ScalaSubClass.scala
package scalapkg
import javapkg.JavaSuperClass
class ScalaSubClass extends JavaSuperClass {
  override def method(javaInnerClass: JavaSuperClass#JavaInnerClass) {
    println("world")
  }
}

I have Java Sun JDK Hotspot 1.6.0_24 and Scala 2.9.0.1 on Linux. This is what happens:

$ cd javapkg
$ javac JavaSuperClass.java
$ cd ../scalapkg
$ scalac -cp .. ScalaSubClass.scala
ScalaSubClass.scala:6: error: class JavaInnerClass in class JavaSuperClass cannot be accessed in javapkg.JavaSuperClass
 Access to protected class JavaInnerClass not permitted because
 prefix type javapkg.JavaSuperClass does not conform to
 class ScalaSubClass in package scalapkg where the access take place
  override def method(javaInnerclass: JavaSuperClass#JavaInnerClass) {
                                                     ^
one error found

Note, if I change JavaSuperClass#JavaInnerClass to simply JavaInnerClass, I get this:

ScalaSubClass.scala:6: error: method method overrides nothing
  override def method(javaInnerClass: JavaInnerClass) {
               ^
one error found

Note: I know this sounds very similar to the common “protected static inner class” Java-compatibility issue in Scala, but I believe this is unrelated because there are no statics anywhere in my example.

I feel like something is wrong, because when I put the same code into a mixed java/scala project in Eclipse, it seemed to compile fine (with the latter JavaInnerClass syntax); it’s only when I compile the Scala code with only the Java byte code (and no Java source code) that I cannot get it to work. Am I just completely missing the correct syntax to refer to a Java inner class, is this a known defect, or should I file a compiler bug? I couldn’t find anything about this exact use case in my searching.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:25:24+00:00Added an answer on May 23, 2026 at 10:25 am

    This is an excellent article that discuss the topic.

    EDIT-1

    My bad, I answered to quickly. This actually may be a bug Mike, I’m trying to see if I can find a hack around. I’ll let you know if I find one.

    EDIT-2

    I’ve tried different things but I can’t find a way to make it work. Mike I’d suggest you to file a bug report.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I writing a report in Visual Studio that takes a user input parameter and
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
I'm writing some Scala code which uses the Apache POI API. I would like
I'm new to Scala, and from what I understand yield in Scala is not
I'm writing a ServletUnitTest trait in Scala to provide a convenience API for ServletUnit
I am new with Scala and I am writing a simple rss reader. I
I'm writing a code generator which produces Scala output. I need to emulate a
I'm writing a Java application using Struts 2, but now I'd like to make
I have a program that takes an image and writes that out to a
I'm writing a scala application using scala swing. I can listen for MouseClicked to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.