generics tag

5 questions


1 answers
150 views
0
A good way to write a generic class definition that does not require a type parameter name

sealed class response<T>{ data class success <T> (value:T): Response <T>() data class fail<T>(valueerrorMessage: String):Response<T>()}fun<T>fetch(onResponse:(Respo...

2 years ago

1 answers
112 views
0
I want to define API method arguments and return values abstractly

(Windows, Java 1.8.0)Currently, I am writing the following code as an API using JAX-RS (Jersey).@Path(API_01)//URL at API call @POST @Produce(MediaType.APPLICATION_JSON) publicResponseObj execute(Req...

2 years ago

1 answers
139 views
0
How do I return to generic type in the method?

If you look at the same example below in the OOP book, If you have an Animal class, each animal has several friends. And the subclasses are Dog, Duck, Mouse, etc. Each of them makes a bark(), a quack(...

2 years ago

1 answers
154 views
0
How do I create a generic array in Java?

Due to the Java generic implementation, it cannot be implemented as follows:public class GenSet<E> { private E a[]; public GenSet() { a = new E[INITIAL_ARRAY_LENGTH]; // error: generic array cr...


1 answers
82 views
0
Is List a subclass of List? Why is Java generic implicitly not guaranteed polymorphism?

It's confusing how Java Generics deals with inheritance and polymorphism.Let's say there's a hierarchy like this.Animal (Parent)Dog - Cat (child) Assuming that there is a DoSomething(List<Animal>...


© 2024 OneMinuteCode. All rights reserved.