generics

With TypeScript, can I type a curried version of getProperty<T, K extends keyof T>

丶灬走出姿态 提交于 2020-01-30 06:32:29
问题 Example from https://www.typescriptlang.org/docs/handbook/advanced-types.html function getProperty<T, K extends keyof T>(o: T, name: K): T[K] { return o[name]; // o[name] is of type T[K] } Curried version: function curriedGetProperty<T, K extends keyof T>(name: K): (o: T) => T[K] { return (o: T) => o[name]; // o[name] is of type T[K] } const record = { id: 4, label: 'hello' } const getId = curriedGetProperty('id') // Argument of type '"id"' is not assignable to parameter of type 'never'.

Java Generics and Raw Types

断了今生、忘了曾经 提交于 2020-01-30 05:17:46
问题 I have the next code: ArrayList value = new ArrayList<Integer>(); // 1 value.add("Test"); // 2 I'm trying to understand line 2. Although I can see that value.add("Test"); compiles without errors, I can't see the reason it doesn't throw a runtime exception. If value is referencing a generic ArrayList object, why Java allows to add a String to it? Can anyone explain it to me? The closest explanation I've found about this is described here, but I still don't understand the core reason: Stack s =

Java static members in a subclass accessed via a generic parent

喜夏-厌秋 提交于 2020-01-30 04:22:11
问题 This seems like a newbish question, but the last time I worked with Java, the language didn't have generics. I have a class hierarchy (names changed to be as generalized as possible): public abstract class AbstractBase { .... } public class ConcreateSubA extends AbstractBase { .... } public class ConcreateSubB extends AbstractBase { .... } ... public class ConcreateSubZZ9PluralZAlpha extends AbstractBase { .... } ... I'm trying to clean up some legacy code, and there's one place where a ton

Suppressing Java unchecked warnings in JSP files

為{幸葍}努か 提交于 2020-01-30 04:14:37
问题 I have a legacy webapp which uses jstl and Struts 1 tags. When I pre-compile the JSP files with Java 5/6, the jstl and Struts 1 tags throw warnings about "unchecked or unsafe operations". For example, if I use the following tag: <%@ page import="/anotherpage.inc" %> The following warning is thrown: [javac] Note: Some input files use unchecked or unsafe operations. [javac] Note: Recompile with -Xlint:unchecked for details. If I recompile with -Xlint:unchecked, I get details about the internal

Passing a Type to a generic method at runtime [duplicate]

你。 提交于 2020-01-30 04:08:24
问题 This question already has answers here : How do I use reflection to call a generic method? (7 answers) Closed 5 years ago . I have something like this Type MyType = Type.GetType(FromSomewhereElse); var listS = context.GetList<MyType>().ToList(); I would like to get the Type which is MyType in this case and pass it to the Generic Type method GetList This is the error I am getting: The type or namespace name 'MyType' could not be found (are you missing a using directive or an assembly reference

Passing a Type to a generic method at runtime [duplicate]

﹥>﹥吖頭↗ 提交于 2020-01-30 04:08:14
问题 This question already has answers here : How do I use reflection to call a generic method? (7 answers) Closed 5 years ago . I have something like this Type MyType = Type.GetType(FromSomewhereElse); var listS = context.GetList<MyType>().ToList(); I would like to get the Type which is MyType in this case and pass it to the Generic Type method GetList This is the error I am getting: The type or namespace name 'MyType' could not be found (are you missing a using directive or an assembly reference

How do I create a generic property in VB.NET?

自作多情 提交于 2020-01-29 15:34:21
问题 I'd like to do something like this: Private _myCollection As IList(Of T) Public Property MyProperty(Of T)() as IList(Of T) Get Return Me._myCollection End Get Set(ByVal value As String) Me._myCollection = value End Set End Property Basically, I want to have a collection of items that may be of any type. Then, I'll be able to do something like this: Dim myPropertyValue as <the type of some value> if (MyProperty.Contains(<some value>)) myPropertyValue = CType(MyProperty(<some value>), <the type

Return unsafe pointer to type parameter

放肆的年华 提交于 2020-01-29 03:45:07
问题 I am trying to define a property that returns a pointer to a generic type argument like so: public class MemWrapper<T> where T: struct { readonly IntPtr pointerToUnmanagedHeapMem; // ... do some memory management also ... public unsafe T* Ptr { get {return (T*)(pointerToUnmanagedHeapMem);} } } The compiler complains that it is not possible to declare a pointer to the managed type T or get its address or size (CS0208). The curious thing is, if I manually replace the generic type parameter by a

Issue with Inheritance when using nested Generic classes in C#

最后都变了- 提交于 2020-01-28 11:28:13
问题 I'm trying to create a class hierarchy such that I can have: SpecificScreenController < ScreenController < Singleton So far I have these set up as: public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour { private static T _instance; public static T Instance{ get{... return _instance;} } } public abstract class ScreenController<T> : Singleton<T> where T : MonoBehaviour { public GAME_SCREEN GameScreen; //many more ScreenController common properties/fields/methods } public

Issue with Inheritance when using nested Generic classes in C#

自闭症网瘾萝莉.ら 提交于 2020-01-28 11:28:07
问题 I'm trying to create a class hierarchy such that I can have: SpecificScreenController < ScreenController < Singleton So far I have these set up as: public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour { private static T _instance; public static T Instance{ get{... return _instance;} } } public abstract class ScreenController<T> : Singleton<T> where T : MonoBehaviour { public GAME_SCREEN GameScreen; //many more ScreenController common properties/fields/methods } public