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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:45:16+00:00 2026-06-12T01:45:16+00:00

public void m1(Integer f) { … } public void m1(Float f) { … }

  • 0
public void m1(Integer f) {
    ...
}

public void m1(Float f) {
    ...
}

public void main() {
    m1(null); // error: the method m1(Integer) is ambiguous for the type Main
    m1((Integer) null); // success
}

Given the above example, we can admit in some ways that null is typed. So why do the following lines print true? Sure o1 and o2 both have no value (i.e. null), but they aren’t from the same type (Integer vs Float). I firstly thought false would have been printed.

Integer i = null;
Object o1 = (Object) i;
Float f = null;
Object o2 = (Object) f;
System.out.println(o1 == o2); // prints true

// in short:
System.out.println(((Object) ((Integer) null)) == ((Object) ((Float) null))); // prints true
  • 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-12T01:45:17+00:00Added an answer on June 12, 2026 at 1:45 am

    All null values are untyped and are equal. You can pass it to different reference types but it makes no difference for comparison purposes.

    It is not the null value which is typed but the reference to the null which can be typed.

    A common question is what happens here

    class A {
        public static void hello() { System.out.println("Hello World"); }
    
        public static void main(String... args) {
            A a = null;
            a.hello();
            System.out.println("a is an A is " + (a instanceof A)); // prints false.
        }
    }
    

    The compiler sees the type of a as an A so the static method is called. But the value referenced is null and untyped.

    The only operations you can perform with null without causing a NullPointerException is to assign or pass it without examining it or comparing it with another reference.

    BTW

    In short: The compiler will select a method based on the type of the reference, at runtime the execution is based on the class of the object referenced. At runtime null is treated as any type or no type or you get a NullPointerException if you try to dereference it.

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

Sidebar

Related Questions

class D { public static void main(String args[]) { Integer b2=128; Integer b3=128; System.out.println(b2==b3);
public class A { public void test(Integer i) { System.out.println(In Wrapper Method); } public
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
public static class TestTask extends AsyncTask<Void, Integer, Integer> { private String stacktrace; public TestTask
public class HttpPostTask extends AsyncTask<Void, Integer, Void> { TextView txtStatus = (TextView)findViewById(R.id.txtStatus); @Override protected
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Init(); backthread tr=new backthread(); tr.execute(0,0,0); } backthread
public void foo(Integer... ids) { Integer... fIds = bar(ids); } public void bar(Integer... ids)
I have a method with the signature public void setFoo(int newFoo) in a model
Consider this code: class test { public static void main(String[] args) { test inst_test
Given this Java code: class Account { private Integer number = 0; public synchronized

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.