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: 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… 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] 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. Re: MyGenericClass vs. Type Erasure: What's the best solution? Programming Software Development by JamesCherrill … passing a "dummy" arg to the constructor whose type has to be <T>, then you can use… 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: MyGenericClass vs. Type Erasure: What's the best solution? Programming Software Development by JamesCherrill There's also a truly hideous workaround... [url]http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ609[/url] 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: 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… Re: Find type of generic collection Programming Software Development by ~s.o.s~ … the way generics are implemented in Java. IMO, the cleanest (type-safe without any warning) approach you can come across can… 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: Warning: Type check on Collections/Lists Programming Software Development by Alex Edwards … allowed is for compatibility between legacy versions of Java (before Erasure types) and of course the current standard. [code=java] import… Data erasure? Please help. Programming Software Development by Alex Edwards … I was going to rename it) by using a menu-type cluster object as well as "action" objects clustered… Re: Data erasure? Please help. Programming Software Development by Alex Edwards …'d be accessing a NULL reference. I could provide a type of trim method that will resize and reallocate the pointer… Re: Find type of generic collection Programming Software Development by chaospie Haven't used generics in a while, but is something like this what your looking for: [code=java] import java.util.ArrayList; public class GenericTest<T> { private Class<? extends T> instance; public GenericTest( Class<? extends T> instance ) { this.instance = instance; } public <T> void … Re: Find type of generic collection Programming Software Development by JamesCherrill Hi chaospie, thanks for the reply. Yes, that's an approach I found (thanks Google) - you may need to make some of those things final, for reasons I coudn't be bothered to read up. It will work, but its the kind of mess I was hoping to avoid. And if I'm going to have to pass a new parameter to the constructors, in this particular app, I may as well… Re: Find type of generic collection Programming Software Development by JamesCherrill [QUOTE]Any "practical" scenario you have in mind which requires you to have true generics? [/QUOTE] Yeah, this came up as part of a fairly complex app, the details of which are not relevant here. I tried to reduce the problem to the simplest form that would have a solution directly applicable to the full problem. The real situation … 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: 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: 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: 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.