generics Questions
3
Solved
I need a linked node to hold some different interface types, so I made it with generics, but the generics type any can't be compared to nil, it shows error as in the comment:
package main
type myI...
3
This is a question that I wondered about since the lambdas had been introduced in Java, and inspired by a related question, I thought that I might bring it up here, to see whether there are any ide...
10
Solved
Is it possible to merge the props of two generic object types?
I have a function similar to this:
function foo<A extends object, B extends object>(a: A, b: B) {
return Object.assign({}, a, ...
Mississippian asked 5/4, 2018 at 22:37
4
Solved
I just want to know for what java.util.Collections.checkedList() is actually used.
I have some code that I know is returning me a List<String> but it's being passed through a chain of messa...
Pili asked 21/7, 2009 at 19:17
3
Solved
I read the following code in "Java - The beginner's guide"
interface SomeTest <T>
{
boolean test(T n, T m);
}
class MyClass
{
static <T> boolean myGenMeth(T x, T y)
{
boo...
Saddlery asked 6/7, 2015 at 11:50
2
I have:
struct Plumbus<'a> {
grumbo: &'a dyn Grumbo,
}
trait Grumbo {
fn dinglebop<T>(&self, x: &mut T) -> bool { false }
}
but I get:
error[E0038]: the trait `Grumbo...
6
Solved
Given a constructor
public MyObject(int id){
ID = id;
}
And two enums:
public enum MyEnum1{
Something = 1,
Anotherthing = 2
}
public enum MyEnum2{
Dodo = 1,
Moustache= 2
}
Is it possibl...
1
I have an existential type defined like this:
trait Collection {
type Element;
}
impl<T> Collection for Vec<T> {
type Element = T;
}
type Existential<T> = impl Collection<E...
Calque asked 24/4, 2019 at 9:25
4
Solved
I know this question has been asked often but I'm unable to find a solution.
How can I get a generic type class name in a Spring injected repository?
Here it is my base repository
public interfa...
2
Solved
.NET 7 recently introduced IParsable as an interface, and I'd like to check for its presence. Some test that will return true if T implements IParsable<T> and false otherwise.
Say I want to r...
Pinnatiped asked 19/11, 2022 at 17:6
4
Solved
Is there a way with C# generics to limit a type T to be castable from another type?
Example:
Lets say I am saving information in the registry as a string, and when I restore the information I would...
6
Solved
Why do I get compiler errors with this Java code?
1 public List<? extends Foo> getFoos()
2 {
3 List<? extends Foo> foos = new ArrayList<? extends Foo>();
4 foos.add(new SubFoo())...
4
Solved
Why cant I use an IEnumerable with params? Will this ever be fixed? I really wish they would rewrite the old libraries to use generics...
Clinic asked 24/1, 2010 at 20:49
4
Solved
EDIT: I changed a bit the example for getting the idea:
Like
<Integer or Float>
...without having to create a common interface and make a subclass for Integer and Float to implement it
...
Rhymester asked 24/7, 2012 at 14:42
2
Solved
I'm trying to use a Class<?> in an if statement, like the following:
public static Model get(Class<? extends FooBase> type, long id )
{
switch (type)
{
case FooType.class:
return n...
3
Solved
I have a class A and a class B extends A
In another class C I have a field
private List<B> listB;
Now, for some unusual reason, I have to implement this method in C
public List<A> ...
Acker asked 7/7, 2010 at 13:14
2
Please take a look at my code:
Object longL = 2548214;
Map<String, Object> map = new HashMap<String, Object>(1);
map.put("LongNumber", longL);
List<Map<String, Object>> re...
0
I have missed a problem with the Java Generic type
public class MyTest {
@Test
public void test1() throws Exception {
List<Integer> list = getMapInstance();
}
public static <T extend...
Conk asked 11/5 at 8:13
5
How can I make a generic template type argument required?
So far, the only way I found to do it is using never but it causes an error to happen at a different place other than the callsite of the ...
Ingressive asked 1/11, 2018 at 21:50
5
Solved
In this tutorial on reflection it states:
[...] because generics are implemented via type erasure which removes all information regarding generic types during compilation
My knowledge was tha...
5
Solved
I have this scenario:
class A<T>
I want a constrain of type Person like
class A<T> where T: Person
and I want A to inherit from B too.
example:
class A<T> : B : where T:...
Yearning asked 8/4, 2014 at 14:33
2
Solved
I'm trying to create a generic version of a NamedTuple, as follows:
T1 = TypeVar("T1")
T2 = TypeVar("T2")
class Group(NamedTuple, Generic[T1, T2]):
key: T1
group: List[T2]
g = Group(1, [""]) #...
Economic asked 25/5, 2018 at 14:2
3
Solved
If I have a class:
class Spaceship<FuelType> {
function prepareForLiftoff() throws {
//Start the countdown!
}
}
I originally assumed that I would be able to override prepareForLiftoff w...
9
Solved
I want to create a class that can store objects conforming to a certain protocol. The objects should be stored in a typed array. According to the Swift documentation protocols can be used as types:...
Lungi asked 22/7, 2014 at 13:21
4
Solved
I have a class like that:
public class Wrapper<T> {
private String message;
private T data;
public String getMessage() {
return message;
}
public void setMessage(String message) {
...
Disentwine asked 13/11, 2011 at 1:27
© 2022 - 2024 — McMap. All rights reserved.