Re: MyGenericClass vs. Type Erasure: What's the best solution? Programming Software Development by JDCyrus … one generic class from inside another, and pass the type parameter from the latter to the former. My assumption,…this didn't work, was that it was forbidden by type erasure. However, the code from the workaround posted above (which… it) does instantiate a generic class using a parameterized type, rather than a hard-coded one; this happens in… MyGenericClass vs. Type Erasure: What's the best solution? Programming Software Development by JDCyrus …here. I'm writing a Java class with a generic type parameter. Among other things, it maintains an internal ArrayList …of the same generic type as itself. In a perfect world, the code would …a perfect world, and this doesn't work because of type erasure. The only solution I can think of is to … Re: MyGenericClass vs. Type Erasure: What's the best solution? Programming Software Development by ~s.o.s~ … this doesn't work because of type erasure.[/quote] Why doesn't it work? Instantiating a type parameter won't work, but instantiating… parameterized classes which accept a type argument will. The below snippet won't work, but what… Re: MyGenericClass vs. Type Erasure: What's the best solution? Programming Software Development by JDCyrus …o.s~;1394703]Why doesn't it work? Instantiating a type parameter won't work, but instantiating parameterized classes which …accept a type argument will. The below snippet won't work, but …couldn't be instantiated, but not why, so I assumed type erasure was to blame. Thank you for helping. Me vs. Type Erasure? Programming Software Development by Alex Edwards …(ClassFullOfReferenceVariables)ref; else System.out.println("Unsupported reference type"); } public <E> E getReference(…/* if(i1 instanceof E){ // obviously wont work due to type-erasure }*/ return e; } } [/code] --and be capable of… Re: Me vs. Type Erasure? Programming Software Development by Ezzaral If I get some time later in the day, I may be able to fiddle around with this a bit, but in the mean time, here is a very extensive FAQ on generics and type erasure that might help: [url]http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html[/url] Re: Generic type doubt Programming Software Development by JamesCherrill … then work through what that code looks like after after type erasure, considering different parameters that could be passed to doStuff at… Find type of generic collection Programming Software Development by JamesCherrill …()); } [/CODE] However, because of the way Java implements generics via type erasure, you can't do that. There are some really ugly… Re: Pass variable to callback function without know type? Programming Software Development by mike_2000_17 … central issue here is something called "type erasure". This is something you encounter for time…library (and the standard `std::function` template) do type erasure on function objects (or function pointers). BTW, your… demonstration has all the essential components of most type erasure techniques in C++. The important thing to understand… Re: Problem with this assignment generic type to raw type Programming Software Development by ~s.o.s~ … class has been compiled. Generics in Java are based on type erasure and are compile time constructs i.e. your code is… on your types in which case the variable becomes the erasure of that upper bound. This is one of the reasons… why type declarations at the class level don't allow "super… Re: serialization of an abstract data type Programming Software Development by Labdabeta What you are asking about is called "type erasure" it is basically the combination of templating and inheriting. …Unfortunately C++ does not support type erasure (as far as I know). As such you have to… Mixing Static and Dynamic Polymorphism Programming Software Development by mike_2000_17 … (as shown in the previous section) or through type-erasure (as will be shown shortly). # Dual Approaches …it's implemented (virtual table or otherwise). ## Type-erasure ## *Type-erasure* is the general term for any technique that circumvents…. And we would call this a type-erasure technique because the type of the policy `Printer` is erased… Node Based Editing required class types Programming Software Development by sciwizeh … to connection for input //WAY TO STORE WHAT TYPE OF BUFFER INPUTS NEED TO BE List<String…gt; outputs;//output connections //WAY TO STORE WHAT TYPE OF BUFFER OUTPUTS ARE abstract Buffer getOutput(String out);//… way I should go, but the problem of type erasure has me confused. What would the proper way … DependencyInjection seem ugly and too much work, Am I doing something wrong Programming Software Development by mgold …, I absolutely hate it. First off, using generics (because of type erasure) is a nightmare. Creating factories for everything that has paramatized… Re: super wild card doubt Programming Software Development by JamesCherrill … files there are no generic types - it's called "type erasure". Your generic info has been "erased" by… (me included) think it's a great shame they used type erasure. As I understand it they took the aproach they did… point [this](http://docs.oracle.com/javase/tutorial/java/generics/erasure.html) explains what and why. Re: my variant class don't accept the structs\class's\enums :( Programming Software Development by mike_2000_17 … the traditional C-style way of doing type-erasure, but in C++, it isn't …any { private: struct base { virtual const std::type_info& type() const = 0; virtual base* clone() const = 0;…bad_any_cast(); }; }; This is the basic type-erasure technique used in C++ almost in any … Re: C++ Property Template Programming Software Development by mike_2000_17 … the property is found. * \tparam MemberType The type of the property value. */ template <typename …self; // good to have a "self" type. typedef MemberType (ClassType::*getter_type)() const; typedef void (…some abstractions for the properties (and possibly, type erasure in this case), in case people want to… Re: my variant class don't accept the structs\class's\enums :( Programming Software Development by mike_2000_17 …/doc/html/variant.html) (discriminated union type, similar to that old C-style variant type in windows.h). If you want to…), which is a kind of ultimate type-erasure device. And if you want to take any type and turn it into a serial… Re: Super-power compare method? <?> Programming Software Development by Cudmore … understand this. Generics work well in source code. However, "type erasure" occurs when compiled, so even if you were to…. The method would need to be overridden for each supported type if it were to be deployed in a compiled library. Re: Reflection/Casting, create arbitrary Objects. Programming Software Development by ~s.o.s~ … easily solved if you are ready to pass around "type" tokens i.e. Class instances to methods. Let's… just a Map instance (given that generics are implemented using type erasure). Re: super wild card doubt Programming Software Development by rahul.ch Hmmm thanks! Read up on type erasure after you explained :) After understanding the concept even I agree with your opinion. Re: Advantages: C++/Java Programming Software Development by Alex Edwards … instantiated, the compiler translates those types by a technique called type erasure — a process where the compiler removes all information related to… type parameters and type arguments within a class or method. Type erasure enables Java applications that use generics… Re: Problem with linked lists and templates Programming Software Development by mike_2000_17 … an example of how to do the type casting for type erasure? I can't seem to find any… examples. Here is a simple example of "type-erasure": void some_function(void* points_to_anything) { // cast the…function, though templates seem cleaner. Exactly, the type-erasure technique is basically a really bad alternative to templates… Re: recursive subclass Programming Software Development by mike_2000_17 … no_barking do nothing fct. Well, the variant of type erasure that I showed was not intended to be used … up my sleeve for that. The basic (non-owning) type erasure pattern can be implemented like this: class AnyDoer { private:… in each object. Yes, that's clear. The type erasure technique that I just showed moves the storage of the… Re: Problem with linked lists and templates Programming Software Development by mike_2000_17 … with that. The node class uses a technique called "type-erasure" (or at least, that's what I understand that…it back and forth to set or get the value. Type-erasure is a horrible technique (and should only be used in… your prof., then he's a pretty horrible prof because type-erasure can be avoided completely (e.g., with templates), can be… Re: std::function with several or none parameters Programming Software Development by mike_2000_17 … to do, I think you need to do a classic type-erasure strategy. Here is what I mean: class events { private: //… Notice here that the trade-off for using a type-erasure technique is that you can only detect the error at…quot;. (2) Have the events class do a type-erasure on the function's type, which means you can (at best) catch … Re: design patterns using C++11 Programming Software Development by mike_2000_17 … implementation to keep track of the original raw-pointer type (and value) that the very first shared-pointer …possible.. Oh.. this is easy. It's a simple type-erasure technique. It certainly adds overhead to the implementation, and …but it's not challenging to achieve. Other examples of type-erasure are `std::function` or `boost::any`. You can also… Re: recursive subclass Programming Software Development by mike_2000_17 … is the way to go This technique is generally called **type erasure**. In this context, you could also call it "non… I briefly mentioned in my tutorial). And, of course, the type erasure technique that I showed is not appropriate here because that… Re: C++ - typedef with variadic operator Programming Software Development by mike_2000_17 …functions present some difficulties when it comes to implementing type-erasure, which is the technique used in implementing `std… what is called an "incomplete type". An incomplete type simply means that the compiler knows that…declaring a pointer or reference to that type, making typedefs or type aliases for it, and declaring variables or… Re: Convert Java Interface to C++ Programming Software Development by vijayan121 … of the template class is identical (except for the type) for all these pointer types. See: [url]http…/c++_practical_programming_122.html[/url] In C++ generic programming, 'type erasure' ("the process of turning a wide variety of …types with a common interface into one type with that same interface") is typically used …