Git Product home page Git Product logo

Comments (7)

FrantaM avatar FrantaM commented on June 15, 2024

Why is (e instanceof java.util.ArrayList) an error? While ArrayList itself cannot be cast to Set, you can have a subclass of ArrayList that can. See http://ideone.com/sqQbM0.

from nb-additional-hints.

markiewb avatar markiewb commented on June 15, 2024

The hint only checks the compile-type of "e". "e" is an Set, so internally
it checks for (java.util.Set instanceof java.util.ArrayList), which returns
false.

With kind regards, markiewb

2015-04-16 11:52 GMT+02:00 FrantaM [email protected]:

Why is (e instanceof java.util.ArrayList) an error? While ArrayList
itself cannot be cast to Set, you can have a subclass of ArrayList that
can. See http://ideone.com/sqQbM0.


Reply to this email directly or view it on GitHub
#50 (comment)
.

from nb-additional-hints.

FrantaM avatar FrantaM commented on June 15, 2024

I can see what it does I'm asking as to why. Instance of ArrayList can be an instanceof Set at the same time so this is still a false positive.

from nb-additional-hints.

markiewb avatar markiewb commented on June 15, 2024

My usecase is to catch the following construct

            java.util.Set set = xxx;
            if (set instanceof java.util.ArrayList) {
                java.util.ArrayList list = set; //<- compile error
            }

With kind regards, markiewb

2015-04-16 12:39 GMT+02:00 FrantaM [email protected]:

I can see what it does I'm asking as to why. Instance of ArrayList
can be an instanceof Set at the same time so this is still a false
positive.


Reply to this email directly or view it on GitHub
#50 (comment)
.

from nb-additional-hints.

btbouwens avatar btbouwens commented on June 15, 2024

Indeed this bug is still active: I see this for f instanceof Inter for an interface Inter which isn't implemented by the type of f itself, but by possible subclasses.

from nb-additional-hints.

jrb0001 avatar jrb0001 commented on June 15, 2024

Still not fixed in v1.6.0.3-SNAPSHOT:

InterfaceA something = new ClassBExtendsCImplementsA();
System.out.println(something instanceof ClassC); // Runtime: true, Netbeans: "Dead instanceof. InterfaceA cannot be assigned to ClassC"

from nb-additional-hints.

markiewb avatar markiewb commented on June 15, 2024

@btbouwens, @jrb0001 , @FrantaM : You are all correct. That hint makes no sense. I will remove it via #70

NB already warns you about invalid combinations.

// For example
if (new Double(42) instanceof java.util.Map) {}

from nb-additional-hints.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.