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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:54:07+00:00 2026-06-08T17:54:07+00:00

To my understanding, if type checking can be done during compilation, the type casting

  • 0

To my understanding, if type checking can be done during compilation, the type casting will be done during compilation and will not incur any runtime overhead.

For example

public Child getChild() {
  Parent o = new Child();
  return (Child) o;
}

Is the type casting done during compilation or during runtime?

And is there any general rule to decide if a type casting is done by javac compiler or by the VM?

  • 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-08T17:54:08+00:00Added an answer on June 8, 2026 at 5:54 pm

    Actually, there are three possibilities in this case:

    1. The javac compiler could perform the optimization.
    2. The JIT compiler could perform the optimization.
    3. The native code by the JIT compiler could include code to do a runtime type check.

    I expect that it is option 1. or 2. but this could be platform specific.


    In fact, on my system the bytecode is not optimized. If any optimization is to occur it will be up the the JIT compiler to do it. (This fits with what I’ve heard … that most Java bytecode compilers do little in the way of optimization before generating bytecodes.)

    Compiled from "Test.java"
    public class Test extends java.lang.Object{
    public Test();
      Code:
       0:   aload_0
       1:   invokespecial   #8; //Method java/lang/Object."<init>":()V
       4:   return
    
    public Child getChild();
      Code:
       0:   new #16; //class Child
       3:   dup
       4:   invokespecial   #18; //Method Child."<init>":()V
       7:   astore_1
       8:   aload_1
       9:   checkcast   #16; //class Child
       12:  areturn
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can someone help to configure JXTA ?? I'm not understanding what type of uri
My understanding is typedef acts as a synonym for a type, or can be
I'm having trouble understanding why I can't reference a scala enum type. The problem
Why isn't every type of object implicitly serializable? In my limited understanding, are objects
For my understanding purpose i have implemented Chain-Of-Responsibility pattern. //Abstract Base Type public abstract
I'm using a bytea type in PostgreSQL, which, to my understanding, contains just a
How to identify the exact file type of a file? For better understanding I
Type-hints can make a huge improvement on execution time where reflection occurs many times.
Note: For brevity's sake, the following will not discern between randomness and pseudo-randomness. Also,
I have some what complex UI requirement, need help in understanding type of control/style/template

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.