Comments (7)
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.
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.
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.
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.
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.
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.
@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)
- Transform to assertNull
- java.lang.NullPointerException at at de.markiewb.netbeans.plugins.hints.structure.MethodNameHint.convert HOT 1
- Detect testMethods with @Test-annotation in a JUnit3-Test
- Hint for replacing < with < and > with > within in pre-section within javadoc
- Replace + with ... hint doesn't appear in return statement HOT 1
- Replace with org.junit.Assert
- Code completion for result-type
- Remove "dead instanceof"-hint HOT 1
- Remove unused private code
- Update dependencies, when updating to NB81
- Convert //-comments to /** */-comments and back
- hint for non-standard order of identifiers (public, static, final, ...)
- NullPointerException at de.markiewb.netbeans.plugins.hints.optional.ReturnForOptional.toFix
- Reduce dependencies
- NullPointerException at org.netbeans.api.java.source.ElementUtilities.enclosingTypeElementImpl HOT 1
- Hints for converting ternary to if and back are missing HOT 2
- Split 'this.'-hint for methods and fields HOT 1
- False positive in lambda inside a method returning Optional
- Replace FileInputStream and FileOutputStream by their JDK7 equivalents HOT 1
- Raise a PR for integrating into Apache NetBeans GitHub HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nb-additional-hints.