type-erasure Questions

2

Solved

I've been using Jackson to serialize/deserialize objects for years and have always found it needlessly complicated to use TypeReference<T> to deserialize List etc. I created a simple helper f...
Diseased asked 11/4, 2020 at 1:6

2

Solved

I defined following methods. class Some { void doSome(Consumer<? super Other> consumer) { } <T extends Collection<? super Other>> T doSome(T collection) { doSome(collection:...
Acadia asked 1/2 at 7:0

8

I read about Java's type erasure on Oracle's website. When does type erasure occur? At compile time or runtime? When the class is loaded? When the class is instantiated? A lot of sites (including...
Barrett asked 4/12, 2008 at 6:13

1

Considering the following code: import scala.reflect.api.Universe object UnqualifiedTypeTag { val RuntimeUniverse = scala.reflect.runtime.universe trait HasUniverse { val universe: Universe ...
Polyneuritis asked 20/2, 2023 at 2:58

1

Here is a simple example: object MatchErasedType { trait Supe { self: Singleton => type T1 lazy val default: T1 def process(v: Any): T1 = { v match { case vv: T1 => vv case _ =&gt...
Benevento asked 11/2, 2023 at 21:28

2

I'm currently trying to dynamically create Akka Stream graph definitions at runtime. The idea being that users will be able to define flows interactively and attach them to existing/running Broadca...
Interoceptor asked 26/4, 2017 at 16:30

3

Solved

I have FinanceRequests and CommisionTransactions in my domain. If I have a list of FinanceRequests each FinanceRequest could contain multiple CommisionTransactions that need to be clawed back. Dont...
Behold asked 26/8, 2011 at 7:13

3

Solved

I have a class called foo_t that has a member called bar which could be any one of the types std::string, int, std::vector<double>, etc. I would like to be able to ask foo_t which type bar ha...
Dobb asked 25/2, 2018 at 21:24

4

I am working in a memory constrained embedded environment where malloc/free new/delete are not advisable, and I'm trying to use the std::function pattern to register callbacks. I do not have access...
Amalgamation asked 13/7, 2017 at 18:44

1

Solved

I am trying to implement a "static" sized function, that uses preallocated store, unlike std::function that uses dynamic heap allocations. #include <utility> #include <cstddef&g...
Reclinate asked 28/7, 2022 at 12:31

3

Solved

The std::unique_ptr template has two parameters: the type of the pointee, and the type of the deleter. This second parameter has a default value, so you usually just write something like std::uniqu...
Babby asked 26/7, 2011 at 11:51

1

Solved

All the tutorials I read about type reification say that we need to use 'inline' when using 'reified', but none of them explain why. Let's say I have a function: inline fun <reified T> doSome...

16

Solved

What's the reason why Java doesn't allow us to do private T[] elements = new T[initialCapacity]; I could understand .NET didn't allow us to do that, as in .NET you have value types that at run-t...
Attic asked 28/5, 2010 at 7:47

2

Solved

Is there type erasure of generics in Rust (like in Java) or not? I am unable to find a definitive answer.
Citrange asked 13/9, 2015 at 3:36

5

Solved

I noticed something while I was derping around with generics. In the example below, doStuff1 compiles but doStuff2 doesn't: public <T extends Foo> void doStuff1(T value) { Class<? extend...
Nephrolith asked 9/8, 2013 at 10:22

1

Solved

I am not sure how to word the title of this question in a concise way. There are a few related questions I have found, for instance this one, but none of them seem to answer the question I have exp...
Nata asked 16/10, 2020 at 15:23

3

Solved

I have two overloaded method having following signatures - def fun(x: Seq[String]): Future[Seq[Int]] = ??? def fun(x: Seq[(String, String)]): Future[Seq[Int]] = ??? Due to type erasure, these meth...
Synclastic asked 12/10, 2020 at 7:19

3

Solved

What is the proper way to convert a Jackson JsonNode to a java collection? If it were a json string I could use ObjectMapper.readValue(String, TypeReference) but for a JsonNode the only options ar...
Toneless asked 30/8, 2016 at 22:8

1

Suppose I have the following structure: public interface A { } public interface B { } public interface B1 extends B { } public interface B2 extends B { } public class C implements A, B1 { pri...
Declaratory asked 8/6, 2020 at 13:27

3

I'm confused about the generic type. I expect that 2.asInstanceOf[A] is cast to the type A, meanwhile, it's cast to Int. Besides that, the input is java.lang.Long whereas the output is a list of In...
Deduction asked 4/3, 2020 at 7:41

2

Solved

I was looking for, in a struct, having a way of having a generic property where the type is defined at runtime like: struct Dog { let id: String let value: ?? } A simple use case where this ca...
Buffy asked 6/2, 2020 at 13:48

2

Solved

In my concrete class I would like to have a function that has the following signature. inline fun <reified T : Comparable<T>> get(key: String): T However I want to extract an interfa...

1

Solved

I'm in a situation where I'm working with data wrapped in an Arc, and I sometimes end up using into_raw to get the raw pointer to the underlying data. My use case also calls for type-erasure, so th...
Torietorii asked 9/1, 2020 at 20:30

1

Solved

In this post: Is it possible to convert a TypeTag to a Manifest? It is indicated that a TypeTag can be converted into a Manifest using the following code: def toManifest[T:TypeTag]: Manifest[T]...
Wessling asked 8/1, 2020 at 0:0

1

Solved

Why does List[scala.Int] type erase to List[Object] whilst Integer in List[java.lang.Integer] seems to be preserved? For example, javap for object Foo { def fooInt: List[scala.Int] = ??? def fo...
Inextensible asked 18/7, 2019 at 17:38

© 2022 - 2024 — McMap. All rights reserved.