Java Generics – argument type and casting

I have a generics problem I am trying to resolve. I’m doing some manual casting and it feels like I’m doing something wrong. I’m a bit new to using generics, so it’s very much possible I am misusing …

How to capture and propagate a wildcard type argument?

I have a couple of classes having identical methods, except with respect to certain parameter types: interface ICls { void doSomething(String key, T value); Map …

How to use one type in method?

I have two forms, one form to create user and one to update user.These forms are similiar and I want to use one type in my method,I wouldn’t like to create two methods one to create user from …

Is it possible to make a generic functional interface with optional parameter(s)?

I’m trying to create a functional interface in Java with a single method (of course) that can take any type of parameter(s) and return any data type (i.e. a generic method). This is what I have so far:…

Java enum with generic attributes

I have been trying to create enum that contains generic attribute, for example: public enum SomeEnum { SOME_VALUE_1(SomeValue1.class), SOME_VALUE_2(SomeValue2.class); private final Class&…

Does it matter if function returns T or object if T can not be inferred from context?

I found the following source code in gson: public T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException { JsonReader jsonReader = newJsonReader(json); T …

Java Generics – quick question on Greater Than Method with Objects

I have an assignment in my Java class, we are learning Generics, I have looked in my notes, my lessons, and even on the internet and I still cant figure out what this last assignment question is …

How to call Scala curry functions from Java with Generics

A Scala code has a retry mechanism which is based on currying function: object RetryUtil { def retry[T](retry: Int, timeout: FiniteDuration)(exc: => T): T = { // } } I want to call this …

Java generics impossible assignment?

Every time I think I understand generics better (and can answer without compiling), I get to an example where this theory breaks. Here is a very simple example: static void consumer(List<? super …

How to create a generic wrapper for just any method call?

I want to create a helper method that can wrap/convert just any sync method call into an async Mono. The following is close, but shows an error: Required type: Mono Provided: Mono<? …