Questions tagged [unchecked-cast]

Unchecked cast means that you are casting from a generic type to a non-qualified type, or the other way around.

51 questions
1
vote
1 answer

Unchecked cast warnings in generic method on parameter that must be used in a List

In the code below, the type parameter D can be either a List or a List> (it is the third generic parameter in the Fields interface but still I might omit it there - but it is present also in the return type of the method).…
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
0
votes
1 answer

Kotlin Generic problem, UNCHECKED_CAST , required:Nothing

@file:Suppress("UNCHECKED_CAST") data class Element( val key: String, val valueOne: T, val valueTwo: T, val comparator: Comparator, val comparatorValue: CompareResult ) enum class CompareResult( val value: Int ) { …
0
votes
1 answer

Java Unchecked Cast from List containing wildcard to List of a specific type

I have the following classes public class PathPart { private final String pathPart; public PathPart(String pathPart) { this.pathPart = pathPart; } public String getPathPart() { return pathPart; } } public class…
mepmerp
  • 701
  • 1
  • 9
  • 16
0
votes
1 answer

How to fix Unchecked cast warning in generic type casting

I'm implementing a list link in the stack. The program successfully passes all the required tests, but I encounter this warning. There is no disruption in the implementation of the program, but I am looking to eliminate this problem. Can you tell me…
matin_mhz
  • 1
  • 2
0
votes
0 answers

How to address "Unchecked cast from Object to CriteriaComboBox" in Eclipse

I'd like to know how to avoid this unchecked cast warning in eclipse even though it might not be necessary since I know what types i'm putting into the object. My CriteriaComboBox extends a RenderedComboBox which extends a JComboBox. My class is of…
simgineer
  • 1,754
  • 2
  • 22
  • 49
0
votes
1 answer

Unchecked Cast warning - shows up for Type parameters but not for Concrete types?

Consider the following snippet: Integer a = Integer.valueOf(23); Double d = (Double) (Number) a; //not unchecked cast List stringList = new ArrayList<>(); List integerList =…
theutonium.18
  • 483
  • 2
  • 7
0
votes
2 answers

Button constraint issues i believe

Hope the weekend is going well. I am working on login and registration pages and having a hard time finding a solution to an unchecked cast error and after checking, it seemed everything is fine on the xml code. the challenge is really frustrating,…
0
votes
0 answers

Avoid unchecked cast in ChoiceBox that populates from Enum

I wrote the following custom ChoiceBox that populates itself from a generic Enum implementing my interface DisplayName below: import java.util.Objects; import javafx.scene.control.ChoiceBox; import javafx.util.StringConverter; public class…
floxbr
  • 144
  • 1
  • 9
0
votes
1 answer

No cast for observer pattern using generics

I was looking to implement an subject-observer pattern where the subject provides its self to the observers when notifying. public class Subject { /** suporting stuff for subject */ private List> observers =…
0
votes
0 answers

How to avoid casting when accessing generic class member

I have a situation where I'd like to allow a user to complete a form, where the input data is a list of either String values or Boolean values. This is very much like the Settings list on any mobile phone, a series of String values and toggles. So,…
Brandon
  • 1,886
  • 2
  • 17
  • 28
0
votes
0 answers

Interesting unchecked cast warning

Given this code: public final class MyMap extends HashMap, MyInterface> { public T put(MyClass key, T value) { return (T)key.getClass().getComponentType().cast(super.put(key,…
Wietlol
  • 1,001
  • 1
  • 10
  • 25
0
votes
1 answer

Why does creating SimpleImmutableMap cause unchecked cast warning?

In the following pretty simple code: public static void test(Map t){ for(Map.Entry e : t.entrySet()){ //The next line causes unchecked cast warning Object o = new…
user3663882
  • 6,957
  • 10
  • 51
  • 92
0
votes
1 answer

Inappropriate 'unchecked assignment' warning in IntelliJ

I have a line saying List configs = filter.getFilterConfig(); and IntelliJ warns me about Unchecked assignment: java.util.List to java.util.List However, the called method says: public…
Sebastian
  • 5,721
  • 3
  • 43
  • 69
0
votes
0 answers

Eclipse Generic Warning : Type safety: Unchecked cast from T to E

How I can avoid generic warnings in the following code? Eclipse Generic Warning : Type safety: Unchecked cast from T to E Is there a way to improve this code. Just putting and removing values from Stack. public static void genericStack(T…
David
  • 504
  • 5
  • 21
0
votes
2 answers

Avoiding unchecked casts with generics with double extending classes?

I have the following code, which I just refactored to this today since I understand what truly means, here is the simplified version: public class Buffer { protected final int bufferType; protected final int…
skiwi
  • 66,971
  • 31
  • 131
  • 216