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 6796407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:27:49+00:00 2026-05-26T18:27:49+00:00

Consider this code: class Outer { class Inner } In Java it would be

  • 0

Consider this code:

class Outer {
  class Inner
}

In Java it would be possible to create an instance of Inner with:

Outer.Inner inner = new Outer().new Inner();

I know I can write this in Scala:

val outer = new Outer
val inner = new outer.Inner

But I wonder if it is possible to express the same without the assignment to outer.

Both

new Outer.new Inner  

and

new (new Outer).Inner

are not accepted by the compiler.

Is there something I’m missing?

  • 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-26T18:27:50+00:00Added an answer on May 26, 2026 at 6:27 pm

    First of all, I doubt that the instantiation in one go is any meaningful — you are like throwing away the Outer instance, keeping no reference to it. Makes me wonder, if you weren’t thinking of a Java static inner class, like

    public class Outer() {
       public static class Inner() {}
    }
    

    which in Scala would translate to Inner being an inner class of Outer‘s companion object:

    object Outer {
        class Inner
    }
    
    new Outer.Inner
    

    If you really want an inner dependent class, and you just want more convenient syntax for instantiating it, you could add a companion object for it:

    class Outer {
       object Inner {
          def apply() = new Inner()
       }
       class Inner
    }
    
    new Outer().Inner()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code: var Someclass = new Class(); var Anotherclass = new Class(); var
Consider this code: import java.util.*; class jm45 implements Comparator<jm45> { private int x; jm45(int
Consider this code: import java.util.regex.*; public class Pattern3 { /** * @param args the
Consider the following code: public class Outer<T> { public class Inner{ } public static
Consider this code from the official OpenJDK source of java.awt.font.TextLayout : public final class
Consider this Java code class A{ //@returns Class object this method is contained in
Consider this code : class MyClass<T> { } class AnotherClass : MyClass<String> { }
Consider this snippet of code: public static class MatchCollectionExtensions { public static IEnumerable<T> AsEnumerable<T>(this
Consider this code... using System.Threading; //... Timer someWork = new Timer( delegate(object state) {
consider this code block public void ManageInstalledComponentsUpdate() { IUpdateView view = new UpdaterForm(); BackgroundWorker

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.