How to use Realm objects with Swift generic type?

I have generic class Child. At some point I want to check if Child object conforms to MyProtocol and I get the error EXC_BAD_ACCESS. At this point I dont know if this is related to Swift or to Realm library. protocol MyProtocol: class { } class Ch...
more »

2017-04-18 21:04 (0) Answers

Type erasure in generics confusion

I was reading concept of type erasure in generics. While executing the below piece of code I got confused. public class CollectionsWild { void Test(Collection<?> t){ System.out.println("Collection"); } void Test(List<I...
more »

2017-04-18 17:04 (2) Answers

instantiating generic interface

I have two interfaces: public interface IReportRow { List<string> ToList(); } public interface IReportPreparer<T> where T : IReportRow { List<T> GetRows(JObject json); string GetAdditionalData(T reportRow); } a c...
more »

2017-04-18 17:04 (3) Answers

Java create generic class with generic type

I'm trying to implement a generic cache class using the DualCache library. When instantiating the DualCache class one also needs to provide a serializer instance which itself is a generic class that should be of the same type as the DualCache its att...
more »

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

How to cast generic type T to interface?

I wrote a generic update method like following: int UpdateBy(Expression<Func<T, bool>> filterExpression, Expression<Func<T, T>> updateExpression) where T : class, new() { int result; //if T implements IModel interface...
more »

2017-04-18 09:04 (0) Answers

What does protected <T> T function() means?

While looking into some code I found out that there is following kind of syntax. protected <T> T Execute(Class<T> returnType){ T t; return t; } What does this mean?? What if I want to save the outcome in some variable of o...
more »

2017-04-18 09:04 (2) Answers

How to inherit class with multiple generics?

I'm trying to extend this class that has multiple generics and extends from multiple interfaces, which is giving me a hard time. Here is the class, public class Transformer<TDtox, TDto, Tvar> : ITransformer<TDto, ToSave<TP, Tvar>>...
more »

2017-04-18 07:04 (1) Answers

Swift not finding the correct type

I am trying to use SwiftHamcrest I have a function func equalToArray<T, S>(_ vector:Array<S>) -> Matcher<T> { let v: Matcher<T> = Hamcrest.hasCount(16) return v } This gives an error Error:(16, 31) 'hasCount' prod...
more »

2017-04-17 19:04 (1) Answers

Kotlin generics super/child classes

Trying to use generic types classes but got following problem, which is: Type mismatch: inferred type is ChildClass but SuperClass<SuperType> was expected open class SuperClass<T> where T: SuperType { fun modifySomething(input:...
more »

2017-04-17 16:04 (1) Answers

Mixing class and function generics in Kotlin?

I'm trying to create an interface that defines a single method. The type of the argument for that method must be a type parameter of the interface, because implementations of the interface will have unique implementations for this parameter. Fine so ...
more »

2017-04-17 14:04 (1) Answers

c# virtual generic factory method

I have a project with a base assembly that uses a factory class. For each sub-project using that base assembly, I then override the factory methods for each sub-type as follows: // BASE FACTORY IN BASE ASSEMBLY public class InitFactory : InitFactory...
more »

2017-04-17 11:04 (0) Answers

Creating a Repository Pattern Interface

I'm new to using interfaces in C#. I was watching a tutorial about it and learned how to use it. I'm really into best practices. On the tutorial, it only uses a Person class on the Interface to do CRUD. I'm just wondering if it's advisable to creat...
more »

2017-04-16 20:04 (1) Answers

Generic QuickSort causing StackOverflowError

This is a practice problem in the Java book I'm working through. Basically, the goal is to sort an array of generic-type elements in increasing order using compareTo. I'm trying to use QuickSort to do it. Here's my code: public static <T extend...
more »

2017-04-15 21:04 (1) Answers

implicit conversion with generics

Sorry for providing such long code list, but I need to understand why derived generics class complains about Implicit Conversion. Error text is below and it is with "CatalogObjectAttribute" class: CatalogChildContainersRepository cannot be used...
more »

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

Use of Java 8 Lambdas with Generics

Is it possible to do this using Predicate interface. I have a client class that utilizes functions provided by a MathUtility class. Whatever the Mathmatical operation it should happen only within the MathUtility class. //in client MathUti...
more »

2017-04-15 19:04 (4) Answers

complementary generic classes

I have two abstract classes: Container, Node One kind of Container will always contain the same kind of Node, and one kind of node will only belong to its corresponding container: NodeTypeA is stored in ContainerTypeA, and no other subclass of Node ...
more »

2017-04-15 14:04 (2) Answers

Can I use `try?` with a generic method?

I have a generic throwing method: func doSomething<T>() throws -> T? { // do something } This is how I want to call it: let obj: SomeClass? = try? doSomething() // a compiler error! But I may not. The compiler gives me an error ...
more »

2017-04-14 19:04 (1) Answers

Is this bad Implementation of interface?

Let's say I wanted to define an interface which represents a call to a remote service. Both Services have different request and response public interface ExecutesService<T,S> { public T executeFirstService(S obj); public T executeSec...
more »

2017-04-14 13:04 (4) Answers

Spring Data JPA Specification with Generics

I will build a filterable DataGrid using Spring Data JPA and Specifications.General use of Specificationsin this way public class UserSpecification implements Specification <User> { @Override public Predicate toPredicate (Root<User&...
more »

2017-04-14 13:04 (0) Answers

How to use RealmCollection for Generic code

I have two Realm models, both of which use primary keys. I want to write a method which can be used to create unique primary keys for any Realm object type I pass to it. From what I gather you can use RealmCollection to write generic code. So I sta...
more »

2017-04-14 09:04 (0) Answers