generics

The type cannot be used as type parameter 'T' in the generic type or method 'BaseController<T>'. There is no implicit reference

坚强是说给别人听的谎言 提交于 2021-01-27 07:51:03
问题 I'm trying to create a generic to simplify my codes (it's a web api project), but at somehow it's ended up becoming more complicated than I expected. What I'm trying to implement is something like this: To simplify my whole real code, this is what I've written: public interface IDatabaseTable { } public class ReceiptIndex: IDatabaseTable { } public interface IBackend<T> where T: IDatabaseTable { } public class Receipts : IBackend<ReceiptIndex> { } public class Generic<T> : SyncTwoWayXI,

The type cannot be used as type parameter 'T' in the generic type or method 'BaseController<T>'. There is no implicit reference

微笑、不失礼 提交于 2021-01-27 07:46:45
问题 I'm trying to create a generic to simplify my codes (it's a web api project), but at somehow it's ended up becoming more complicated than I expected. What I'm trying to implement is something like this: To simplify my whole real code, this is what I've written: public interface IDatabaseTable { } public class ReceiptIndex: IDatabaseTable { } public interface IBackend<T> where T: IDatabaseTable { } public class Receipts : IBackend<ReceiptIndex> { } public class Generic<T> : SyncTwoWayXI,

Java object with variable-dimensional array

梦想与她 提交于 2021-01-27 07:40:50
问题 I'm trying to parse a GeoJSON using Gson, and I have an JSON that looks something like this (simplified): {"type": "FeatureCollection", "features": [ { "type": "Feature", "name": "Afghanistan", "geometry": { "type": "Polygon", "coordinates": <<a 3-dimensional double array (double[][][] in Java)>> } }, { "type": "Feature", "name": "Indonesia", "geometry": { "type": "MultiPolygon", "coordinates": <<a 4-dimensional double array (double[][][][] in Java)>> } }, //etc... ] } I need to have a java

Java generic arithmetic

丶灬走出姿态 提交于 2021-01-27 06:32:18
问题 I'm trying to create some Java classes, that should work with either float or double numbers (for simulation purposes I am required to support both). The classes need to do some basic arithmetic and also require use of trigonometric functions (sin, cos, atan2). I tried to do a generic approach. As Java does not allow primitive types in generics and MyClass<T extends Number> does indeed allow Double and Float, but makes basic arithmetic impossible, I build a wrapper class around Double and

Java generic arithmetic

橙三吉。 提交于 2021-01-27 06:32:13
问题 I'm trying to create some Java classes, that should work with either float or double numbers (for simulation purposes I am required to support both). The classes need to do some basic arithmetic and also require use of trigonometric functions (sin, cos, atan2). I tried to do a generic approach. As Java does not allow primitive types in generics and MyClass<T extends Number> does indeed allow Double and Float, but makes basic arithmetic impossible, I build a wrapper class around Double and

Call constructor from derived type via this in typescript

眉间皱痕 提交于 2021-01-27 05:57:46
问题 In my typescript I'm trying to create/clone an child-object via a method in the base-class. This is my (simplified) setup. abstract class BaseClass<TCompositionProps> { protected props: TCompositionProps; protected cloneProps(): TCompositionProps { return $.extend(true, {}, this.props); } // can be overwriten by childs constructor(props: TCompositionProps){ this.props = props; } clone(){ const props = this.cloneProps(); return this.constructor(props); } } interface IProps { someValues: string

How to set a generic constraint that the type is a List?

て烟熏妆下的殇ゞ 提交于 2021-01-27 04:53:08
问题 private static void PrintEachItemInList<T>(T anyList) Where T:System.Collections.Generic.List<T> { foreach (var t in T) { //Do whatever } } In the above code (which is wrong) all I want to do it to set a constraint that T is a List. The aim is not to get this example to work, the aim is to understand how can I set a constraint that the type is a list? I am an amateur in generics and am trying to figure things out :( 回答1: Maybe you want two type parameters, as in: private static void

Implementing Multilevel Java Interfaces in Scala

爷,独闯天下 提交于 2021-01-27 04:42:33
问题 I have following hierarchy in java for my interface public interface Identifiable<T extends Comparable<T>> extends Serializable { public T getId(); } public interface Function extends Identifiable { public String getId(); } public abstract class Adapter implements Function { public abstract String getId(); } When I try to implement Adapter in scala as follows class MultiGetFunction extends Adapter { def getId() : String = this.getClass.getName } I am getting following error Multiple markers

How to invoke System.Linq.Enumerable.Count<> on IEnumerable<T> using Reflection?

泪湿孤枕 提交于 2021-01-27 04:22:16
问题 I have a bunch of IEnumerable Collections which exact number and types is subject of frequent changes (due to automatic code generation). It looks something like this: public class MyCollections { public System.Collections.Generic.IEnumerable<SomeType> SomeTypeCollection; public System.Collections.Generic.IEnumerable<OtherType> OtherTypeCollection; ... At runtime i want to determine each Type and it's count without having to rewrite the code after every code generation. So i am looking for a

Java - A method that takes vararg and returns arraylist?

本秂侑毒 提交于 2021-01-27 04:18:08
问题 I'm not entirely comfortable with generics and thus haven't found a solution to this yet. I have these three methods: public static List<ObjectA> objectAAsList(ObjectA ... items) { return new ArrayList<>(Arrays.asList(items)); } public static List<ObjectB> objectBAsList(ObjectB ... items) { return new ArrayList<>(Arrays.asList(items)); } public static List<ObjectC> objectCAsList(ObjectC ... items) { return new ArrayList<>(Arrays.asList(items)); } How can I create a single method that takes a