Casting Object From Class To Fit Generic

I have a Map that receives a Class<? extends EntityBase> and gives a GenericRenderer<? extends EntityBase>. Inside the GenericRenderer<? extends EntityBase>, there's a method called draw that takes a SpriteBatch and an object that e...
more »

2017-05-20 22:05 (1) Answers

swift generic parameter issue

What is wrong with the code below?: // Returns a list of news sources for the given category func loadNewsSources() -> [NewsSource] { return fetchEntity<NewsSource>(name: "NewsSource") } // Returns the list of categories func loadC...
more »

2017-05-20 22:05 (0) Answers

Understanding generic collection behaviors

When trying to better understand generics, I created two collections with different bounds. Note that I'm not gonna paste the class definitions here as they are self-explanatory. Also, to make things simple, everything is a class (no interfaces here)...
more »

2017-05-20 04:05 (0) Answers

In django, how generic view works

I have started learning django, I'm not sure how generic view works. I read django documentation several times, I can't gain clear understanding of how generic view works. Very strange but it works well. It retrieves data from the database and render...
more »

2017-05-20 00:05 (2) Answers

Creating generic Swift createOrUpdate method

I'm currently trying to create a generic createOrUpdate function. Ideally I want to be able to, on any subclass of NSManagedObject, call: Type.createOrUpdate(withID: id) { type in // Code goes here assigning variable on the object } Where Type is...
more »

2017-05-19 16:05 (0) Answers

Java Generics - Mixed Object Maps

I'm still getting used to Java Generics however I'm currently in the process of updating an application written prior to generics to use the latest version of java. Problem is the code was not written with type safety in mind! We have a whole bunch...
more »

2017-05-19 15:05 (6) Answers

swift convenience init and generic class

I have a problem creating a convenience init method that then calls a designated init on a class with generic type parameters. Here is the swift 3.1 XCode Version 8.3.2 (8E2002) playground protocol A { var items: [String] { get set } func d...
more »

2017-05-19 11:05 (1) Answers

Generic Types Return in Typescript

I have a Interface find which consists of method cal(); Class a1 and a2 implements the interface. a1 returns a number while a2 returns string. How can i define a single interface to solve my issue. The below is having the snippet of what is mentione...
more »

2017-05-19 07:05 (1) Answers

C# - Method with Generic Property

I've seen plenty of examples of how to use generic Objects in C#, but can I have a generic property for a static object? I have 2 distinct lists of Providers: List<Providers> OldProviders List<Providers> NewProviders OldProviders has ...
more »

2017-05-18 18:05 (1) Answers

F-bounded type generic vs abstract type

I have a trait and a case class: trait Foo[T <: Foo[T]] { def self: T } case class Bar() extends Foo[Bar] { def self = this } I would like to create a type that can take case classes that extend Foo. If I create a trait using generics: tr...
more »

2017-05-18 18:05 (1) Answers

C#: Switch return value type depending on a value

I need an advice, please. The situation is as follows: I have a library for operationing with some of hardware. One of the parameters of the machine is Quant (how many products should be in a package). It can be of three types: *quant type | value ...
more »

2017-05-18 15:05 (2) Answers

Get Generic type Realm Objects from Realm

The goal I want to accomplish is generic response caching via Realm. The API client uses Retrofit. In retrofit callback I want to cache the incoming responses in Realm. The callback is generic and I want to apply it to many Retrofit calls. The Callba...
more »

2017-05-18 15:05 (1) Answers

Android and generic pattern

I recently discovered the following pattern in android classes (Intent): AClass c = data.getParcelableExtra("name"); signature: public <T extends Parcelable> T getParcelableExtra(String name) Further down the trail there is a cast: publi...
more »

2017-05-18 10:05 (1) Answers

Generics in loop, trying to avoid a cast

I have a method call in a loop currently that does not compile: for (Example example : Util.getExample(List.class)) { // Do something with example } Util: public class Util { public <T> T getExample(Class<T> clazz) { /...
more »

2017-05-18 06:05 (3) Answers

C# Resolving a Type as generic type

I'm using reflection to dynamically create objects var type = Type.GetType("Demo.Namespace.AnimalViewModel, Demo.Assembly", true); var fooType = Type.GetType("Demo.Namespace.Foo, Demo.Assembly", true); Activator.CreateInstance(type) as AnimalViewMod...
more »

2017-05-17 23:05 (1) Answers

Java Iterator (Inner Class) Check

could you please double-check the code for any mistakes or possible improvements. What I need to do is to implement an iterator as it says in the following interface: /** * Returns an iterator that enumerates every * element in the collection, start...
more »

2017-05-17 19:05 (0) Answers

is it safe to remove a generic type constraint?

interface IFoo<in T> where T : Bar { Do(T bar); } Is it possible to break anything by removing the constraint on T? I don't think you can break any implementation of IFoo because they either implement it with a concrete type MyFoo : IFoo...
more »

2017-05-17 17:05 (0) Answers

Reflection Filter types by Generic Base

I'm trying to reflect into an assembly and get out all of the types who derive from a generic type. protected List<Assembly> _assemblies = new List<Assembly>(); public List<Type> FilterByType<T>() { return this._assembl...
more »

2017-05-17 17:05 (2) Answers