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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:48:25+00:00 2026-06-18T04:48:25+00:00

Only for example lets consider the class ClassFileAssembler from the sun.reflect package. This class

  • 0

Only for example lets consider the class ClassFileAssembler from the sun.reflect package.

This class is a package local class:

class ClassFileAssembler implements sun.reflect.ClassFileConstants {...

So we can not use even its name ClassFileAssembler, we can not import it directly – it will lead to a compiler error.

However we can create a package named sun.reflect in our project and use the ClassFileAssembler name internally in this package – Java compiler will think that we are inside the ClassFileAssembler‘s package.

If so, why not to try to get a reference to a class object, i.e. ClassFileAssembler.class?

Class<ClassFileAssembler> classFileAssemblerClass = ClassFileAssembler.class;

Unexpectedly this code leads to a run-time error: java.lang.IllegalAccessError: tried to access class sun.reflect.ClassFileAssembler from class sun.reflect.Test.

However we still able to get the ClassFileAssembler class object:

Class<ClassFileAssembler> aClass = (Class<ClassFileAssembler>)Class.forName("sun.reflect.ClassFileAssembler");

It works fine and gives us a full class description.


So, the questions are:

1) What is the difference between techniques, how Class.forName0 retrieves reference to class object, and how .class does it?

2) Why do they have such different security checks?

3) What’s the reason to protect .class reference in such way?

4) Do these techniques use different class loaders?

  • 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-18T04:48:26+00:00Added an answer on June 18, 2026 at 4:48 am

    If you check the javadoc of Class#forName, you will see that:

    Note that this method does not check whether the requested class is accessible to its caller.

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

Sidebar

Related Questions

I am trying to display(block,none) select boxes(in this example only one select box) through
Some commands like svn log, for example will only take one input from the
The example on this page only shows Groovy assertions without parentheses. assert a !=
My example is similar to this - The only problem is I cannot rewrite
Lets consider some cases: _windsor.Register(Component.For<IProductServices>().ImplementedBy<ProductServices>().Interceptors(typeof(SomeInterceptorType)); In this case, when I ask for a IProductServices
I have an issue with an SQL Query. Lets take this example data itemID
I need to upload an ics file to a REST API. The only example
The Mongoid documentation only gives one example of doing a wildcard search: Person.where(first_name: /^d/i)
An example collection (showing models only): [ { name: Bob date: Thu Mar 29
I only want a simple Splash Screen Example. Get the Code, Insert my picture,

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.