public class CastTest
{
publicstatic void main (String[] args) throws CloneNotSupportedException
{
CastTest ct1 = new CastTest ();
// The cast of ct1 is obviously redundant (although the cast of the result is necessary)
CastTest ct2 = (CastTest) ((CastTest)ct1).clone ();
}
}
Description
public class CastTest
{
publicstatic void main (String[] args) throws CloneNotSupportedException
{
CastTest ct1 = new CastTest ();
// The cast of ct1 is obviously redundant (although the cast of the result is necessary)
CastTest ct2 = (CastTest) ((CastTest)ct1).clone ();
}
}
I found the same problem. Here is my example.
BTW you should edit the title from "Reundant" to "Redundant" because I didn't find this Jira when I searched initially.
TestRedundantCast.java
package org.intellij;
import java.util.*;
/**
* User: Alex
*/
public class TestRedundantCast
{
void test() {
Iterator it = ((List) Arrays.asList("1", "2","3")).iterator();
}
}
If I Introduce variable for the List expression, then the redundant type cast will be flagged.
TestRedundantCast.java-After Introduce Variable
package org.intellij;
import java.util.*;
/**
* User: Alex
*/
public class TestRedundantCast
{
void test() {
List list = (List) Arrays.asList("1", "2", "3");
Iterator it = list.iterator();
}
}
Similarly for Gibson's example, if you Introduce variable for the expression ((CastTest)ctl) first, then the reduandant type cast will be flagged.
AlexL - 29 Sep 07 12:35 I found the same problem. Here is my example.
BTW you should edit the title from "Reundant" to "Redundant" because I didn't find this Jira when I searched initially.
TestRedundantCast.java
package org.intellij;
import java.util.*;
/**
* User: Alex
*/
public class TestRedundantCast
{
void test() {
Iterator it = ((List) Arrays.asList("1", "2","3")).iterator();
}
}
If I Introduce variable for the List expression, then the redundant type cast will be flagged.
TestRedundantCast.java-After Introduce Variable
package org.intellij;
import java.util.*;
/**
* User: Alex
*/
public class TestRedundantCast
{
void test() {
List list = (List) Arrays.asList("1", "2", "3");
Iterator it = list.iterator();
}
}
Similarly for Gibson's example, if you Introduce variable for the expression ((CastTest)ctl) first, then the reduandant type cast will be flagged.
BTW you should edit the title from "Reundant" to "Redundant" because I didn't find this Jira when I searched initially.
If I Introduce variable for the List expression, then the redundant type cast will be flagged.
Similarly for Gibson's example, if you Introduce variable for the expression ((CastTest)ctl) first, then the reduandant type cast will be flagged.