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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:29:53+00:00 2026-06-05T11:29:53+00:00

I just started learning Java very recently, coming from a C# background. When I

  • 0

I just started learning Java very recently, coming from a C# background.

When I started using Collections, I noticed that Arrays.asList() returns an ArrayList<T> object.

What I don’t understand, is, however, that according to the code listing at ‘docjar‘ (line 2834) labels ArrayList<T> as private.

How can I be using an object that has been explicitly marked as hidden from me? Or (and this is what I suspect), does private have some sort of different meaning to the one I’m assuming?

(Also, I note that that class is marked as static, which also confuses me, but I’ll ask that in a separate question)


Edit: Example in C# that throws up a compiler error:

public class PubClass {
        private class Blah {

        }

        public Blah GetBlah() {
            return new Blah();
        }
}

Gives: Inconsistent accessibility: return type ‘Namespace.PubClass.Blah’ is less accessible than method ‘Namespace.PubClass.GetBlah()’

  • 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-06-05T11:29:54+00:00Added an answer on June 5, 2026 at 11:29 am

    The ArrayList that is returned to you implements List and all of the methods contained in that interface. Since List is public, you know about those methods and can call on them.

    The reason that ArrayList is private is because there is no reason for it to be public: It doesn’t provide any additional functionality other than what the List interface provides.

    /edit
    Your example doesn’t mimic what’s going on here:

    public interface List<T> {
        /** snip */
    }
    
    public class Arrays {
        private static class ArrayList<T> implements List<T> {
            /** snip */
        }
    
        public <T> List<T> asList(T... arr) {
            return new ArrayList<>(arr);
        }
    }
    

    In your example, you are trying to return an instance of a private class which the outside caller has no knowledge of. In the Arrays example, the object being returned is actually a List (take a look at the return type), not a private ArrayList.

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

Sidebar

Related Questions

I just started learning C++ (coming from Java ) and am having some serious
G'Day Programmers, I am from Java background however I have just started learning C++
I just started learning C++(coming from Java & Python) and am trying to learn
I just started learning Ruby coming from Java. In Java you would use packages
I just recently started learning Java. I have a question which is more about
I've just started learning Spring (and Java) and I'm putting together an application that
Ok so I've just started learning java (I usually program in Objective-C). My first
I've just started learning Java (about a week ago) and the last few days
I've just started learning LWJGL (Java OpenGL), and i'm encountering an enormous amount of
I am in an introductory java course and we just started learning about inheritance.

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.