All Questions
18,136 questions
Advice
0
votes
4
replies
85
views
Generic Type Info at Runtime (Java)
I was reading about Generics from the Eleventh Edition of "Java The Complete Reference", specifically the "Run-Time type Comparisons with a Generic Hierarchy" part.
I was confused ...
Advice
0
votes
8
replies
133
views
How can I allow the user to use class specific methods in generic class T?
I am making a custom LinkedList<T> in Java, as a way to learn more about data structures, and I am trying to make a search method that filters items based on the input, but I ran into an issue. ...
1
vote
3
answers
111
views
How to call a method with generic parameter of a self referencing generic interface?
If given a generic interface of which generic is a reference to this generic interface itself, and this interface has a method with parameter as generic type. After implementing this interface with a ...
1
vote
1
answer
109
views
Android Custom UI Component with Generic Type
I have created a custom spinner in Java for Android and my class uses generics as such
public class TLPSpinner<T> {
I have an event that fires when a object is selected and if instantiate the ...
1
vote
0
answers
97
views
Java interface return specific raw type with different generic type parameter [duplicate]
Is it possible to Java to model a (generic) interface that defines a method that is required to return a generic type that is required to be of a certain raw class? I want to model a container-like ...
4
votes
2
answers
214
views
Java 21 and Generic types wildcard capture issue
I am working on a small side project that uses a very simple command handler pattern for dispatching command classes to handler classes. I come from a C# background, and am running into an issue with ...
0
votes
1
answer
117
views
incompatible types: inference variable V has incompatible bounds (SSE / Jackson)
With the deprecation of MappingJacksonValue in spring boot 4/Jackson 3, I'm trying to figure out how to serialize my objects based on a JsonView.
I have the following SSE endpoint :
@GetMapping(...
1
vote
0
answers
126
views
How to find fragment interface generic type
I am trying to create a custom generic repository using the fragment interface approach as described in this article: https://docs.spring.io/spring-data/jpa/reference/repositories/custom-...
Advice
0
votes
4
replies
72
views
Lower Bounded Wildcards: is it about superType or subType
Oracle documentation mentioned it clearly.
a lower bounded wildcard restricts the unknown type to be a specific type or a super type of that type.
To write the method that works on lists of Integer ...
3
votes
3
answers
156
views
Symbol not found error with complex generics and lambda arrangement
The following test renders fine in my IDE (Eclipse), but fails to compile when building via Maven.
The compiler error is shown in the comment line in the code block below.
It looks like the compiler ...
1
vote
0
answers
141
views
ClassCastException when comparing elements in custom ArrayOrderedList using Comparator
I am implementing an ordered list that automatically inserts elements in the correct sorted position using a Comparator. The list is built from scratch (not using java.util.ArrayList) and uses an ...
-3
votes
3
answers
267
views
How can I generically convert a String value into an instance of a given Comparable type in Java?
I’m trying to implement a generic utility method that takes a String value and a Class<?> type, and returns an instance of that type.
The context: This value represents data from a JPA column, ...
3
votes
2
answers
123
views
Any way to check a cast to a generic?
I am working on a Spring Boot application and there I use JWE - tokens. When generating these tokens I serialize a given DTO. As an example, the generation of an AccessToken looks like this:
public ...
9
votes
2
answers
204
views
Why is Java unable to infer the type when comparing Map.Entry objects?
Why does the following cause a compilation error?
One
Map<Integer, Integer> map = new HashMap<>();
List<Integer> numList = map.entrySet().stream()
.sorted(Comparator....
2
votes
3
answers
201
views
Why does Java give a warning for casting Collection<? extends Number> to List<Number> but an error for assignment?
I’m trying to understand the difference between assignment and casting in Java generics. Consider the following examples:
List<Integer> ints = new ArrayList<>();
List<Number> nums = ...