What is the erasure of a bounded generic type?

I have a class with generics. I know that generic type information is stripped at runtime, but this is with a bound type. I thought that at compilation java.lang.Object is replaced with the bound type. If I know that everything will always be at l...
more »

2017-02-22 18:02 (1) Answers

Generic addListener in Java

I'm working on a program that need to react to different custom events and listeners. I'm trying to make it short using generics, the fact is, I don't understand where is my mistake. Here my code : The listeners and the event : public interface M...
more »

2017-02-22 18:02 (2) Answers

Scala methods with generic parameter type

I have been working with Scala for close to a year, but every now and then I come across a piece of code that I don't really understand. This time it is this one. I tried looking into documents on "scala methods with generic parameter type", but I am...
more »

2017-02-22 15:02 (1) Answers

Rust type-level multiplication

I'm trying to implement type-level multiplication in Rust. Addition is already working, but I got issues with a "temporary" type variable. The code: use std::marker::PhantomData; //Trait for the type level naturals trait Nat {} impl Nat for Zero ...
more »

2017-02-22 13:02 (1) Answers

Set cellDelegate using generic

Hi guys how are you? Hope you guys are fine. I need a little help and i thank you in advance. I have a custom delegate in my custom cell, like this: protocol customTableViewCellDelegate: NSObjectProtocol { func buttonPressed(customCell: custom...
more »

2017-02-22 11:02 (1) Answers

How do I cast to generic type?

The following code produces an "unchecked or unsafe operation" warning, how can I cast the Object o to type T without causing the warning? I know that I could suppress the warning, but I want to know the "correct" way. public class MyType<T>...
more »

2017-02-21 22:02 (1) Answers

How can I get the type of T from the type of T?

I am trying to rewrite a framework my organization uses into .Net Core; specifically the Generic Repository at this point. I am stuck on the following issue. We have a BaseEntity defined as follows: public abstract class BaseEntity<T> : IBas...
more »

2017-02-21 19:02 (1) Answers

Create Generic Realm repository in Swift

I have been struggling with solving a problem which I am pretty sure leads me to adopt the Type-Erasure technique but I am not 100% sure. I have tried several different times and have felt close but ultimately have failed. I will try to simplify my p...
more »

2017-02-21 14:02 (1) Answers

Avoiding repeating code in swift

In following code, based on the string comparison I am deciding on which VC will be shown. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { dataObj = frc.object(at: indexPath) as! Data_Object var pvc: UIViewCo...
more »

2017-02-21 10:02 (4) Answers

F# type constraint with Enum type

I would like to write an F# function that takes a generic enum value and, let's say, doubles its underlying integer value. Fortunately, there's a built-in function called int that converts an enum to an integer, so this should be easy, right? Here's ...
more »

2017-02-21 03:02 (1) Answers

Referring to own type in Swift?

When in a class, how to refer to the class itself when declaring closure parameters? In the example below, what type to place in place of Self so that when constructing Foo, the closure parameter also becomes Foo and similarly for AnotherFoo? class...
more »

2017-02-21 00:02 (1) Answers

Replace generics inside ParameterizedTypeName

Can I use a mapping to replace generics with a known class? Right now I have this: ParameterizedTypeName.get(parameter.asType()) which gets returned as java.util.List<M> I also have a map that says "M" -> "MyModel" (both strings) How ca...
more »

2017-02-20 23:02 (0) Answers

TypeScript: anonymouse class factory

My TypeScript v2.2. I have this class factory: export class A { name: string; } export function makeConstructor(name: string) { const newClass = class extends A { }; newClass.prototype.name = name; return newClass; } TypeScript throw err...
more »

2017-02-20 08:02 (0) Answers