Questions tagged [type-parameter]
A type parameter is a parameter whose value is a type.
type-parameter
535
questions
0
votes
2
answers
50
views
Scala 3 generic method type parameter not working
Works:
trait Transformer[A, B] {
def transform(a: A): B
}
class TransformerImpl extends Transformer[Int, String] {
override def transform(value: Int): String = {
value.toString
}
}
This is ...
0
votes
0
answers
15
views
My code has a 'Type parameter cannot be instantiated directly' error. How do i solve it?
Type parameter 'UserModel' cannot be instantiated directly
userModel = new UserModel (id, email, password, new Constants().equals("students"));
I tried:
public class Register<UserModel>...
1
vote
1
answer
41
views
How can I parameterise this method and make it more flexible?
I'm writing a method to create Quartz scheduling jobs in C#. Currently it looks like this.
private async Task BuildJobs(int startHour, int endHour, int intervalOffsetSeconds = 0)
{
try
{
...
0
votes
0
answers
28
views
Use of generic cast operation in Java
Consider the following code snippet:
public static <T> T convertInstanceOfObject(Object o) {
try {
T rv = (T)o;
return rv;
} catch(java.lang.ClassCastException e) {
...
0
votes
0
answers
35
views
Min(IEnumerable<Double>) vs Min<TSource>(IEnumerable<TSource>)
Say I have a List<double> called nums. If I want to get the minimum of nums, which is a sequence of doubles, I have two options:
use Min(IEnumerable<Double>) -- i.e. do double minNum = ...
0
votes
1
answer
67
views
pass a System.Reflections.Type in to generic component @typeParam on blazor component
I want to get my type from the database and then use a type variable to pass the type to the component. The reason why I'm not just strongly typing it is because we want to be able to switch the type ...
1
vote
2
answers
54
views
Enforcing a common template type parameter among two template type parameters that are themselves templates
In C++, is there any way to ensure that two or more template type parameters are themselves template types with a common template type parameter?
Let's say that I have this:
struct ArbitraryType {};
...
-3
votes
1
answer
52
views
Java interface generic method implementation problems
I have an interface IHuman.java
public interface IHuman<K, V> {
V execute(K request) throws Exception;
}
and I have an implementation, MaleHuman.java
public class MaleHuman implements ...
0
votes
1
answer
74
views
Specify arithmetic operation before backing type is known?
I'm trying to write an interface through which users should be able to pass arbitrary arithmetic functions independent of numeric type, and then helper code would bind them to appropriate backing ...
0
votes
1
answer
136
views
How do I find out how to fill the missing AES type parameter in AesGcm<Aes, NonceSize, TagSize = U16>?
I'm using AES256-GCM, but with 12-byte tags for compatibility reasons.
Therefore I need to use the generic AesGcm
Struct aes_gcm::AesGcm source ·
pub struct AesGcm<Aes, NonceSize, TagSize = U16>...
0
votes
0
answers
11
views
I am trying to create a way to mergeSort with generics. Why does Java keep saying that I am converting my generic type E[] into an integer?
Java is showing the error on lines 11, and 13. Incompatible types: E[] cannot be converted to int.
package holdClasses;
public class sortMethods<E> {
public static <E extends Comparable&...
0
votes
1
answer
51
views
Flutters hot reload not working in typed class
I've got a stateful widget that has a type parameter, and code-changes within it are not picked up by hot reload.
I can replicate the behaviour in a newly created project (see example below). If I ...
0
votes
0
answers
28
views
How to call a Blazor component with Typeparameters from menu with href
I have a Blazor component, that implements thre type paramters like this
@typeparam T where T : class
@typeparam V where V : class
@typeparam P where P : class
I use this component like this
<...
2
votes
1
answer
78
views
How to declare datatypes with type parameters in Z3 Java API?
With Z3 it is possible to declare custom datatypes (i.e., records) that take type parameters. For example, a Pair that takes the types T1 and T2 for its first and second element respectively, is ...
1
vote
1
answer
396
views
How to extract type parameters using reflection [duplicate]
Context: I'm writing a generic auto-mapper that takes two types of structs, checks each field of said structs for a given tag, then copies the value from the source struct to the target struct ...