generics

Raw use of parameterized class

寵の児 提交于 2020-06-24 21:47:11
问题 I wrote a helper method for getting values of static fields of specified type via reflection. The code is working fine, but I am getting "raw use of parameterized class" warning on line: final List<Collection> fields = getStaticFieldValues(Container.class, Collection.class); The issue is that type parameter T can be generic type. Is there way to rewrite method getStaticFieldValues to work around this issue? Code listing: import static java.util.Arrays.asList; import static org.junit.Assert

F# - Understanding types that use generics

匆匆过客 提交于 2020-06-23 16:07:44
问题 I am having an F# exam in 10 days and as I am currently doing old exam sets, I ran into a problem understanding generics and especially types that have two polymorphic arguments. The questions should be rather easy to solve, but how it works syntactically, I am not sure. The old exam question is as follows: The following type Sum<'a,'b> comprises two different kinds of values type Sum<'a,'b> = | Left of 'a | Right of 'b Now I need to write two values of type Sum<int list, bool option> , one

F# - Understanding types that use generics

独自空忆成欢 提交于 2020-06-23 16:06:31
问题 I am having an F# exam in 10 days and as I am currently doing old exam sets, I ran into a problem understanding generics and especially types that have two polymorphic arguments. The questions should be rather easy to solve, but how it works syntactically, I am not sure. The old exam question is as follows: The following type Sum<'a,'b> comprises two different kinds of values type Sum<'a,'b> = | Left of 'a | Right of 'b Now I need to write two values of type Sum<int list, bool option> , one

F# - Understanding types that use generics

ぐ巨炮叔叔 提交于 2020-06-23 16:06:09
问题 I am having an F# exam in 10 days and as I am currently doing old exam sets, I ran into a problem understanding generics and especially types that have two polymorphic arguments. The questions should be rather easy to solve, but how it works syntactically, I am not sure. The old exam question is as follows: The following type Sum<'a,'b> comprises two different kinds of values type Sum<'a,'b> = | Left of 'a | Right of 'b Now I need to write two values of type Sum<int list, bool option> , one

F# - Understanding types that use generics

半腔热情 提交于 2020-06-23 16:05:48
问题 I am having an F# exam in 10 days and as I am currently doing old exam sets, I ran into a problem understanding generics and especially types that have two polymorphic arguments. The questions should be rather easy to solve, but how it works syntactically, I am not sure. The old exam question is as follows: The following type Sum<'a,'b> comprises two different kinds of values type Sum<'a,'b> = | Left of 'a | Right of 'b Now I need to write two values of type Sum<int list, bool option> , one

C# Generics : how to use x.MaxValue / x.MinValue (int, float, double) in a generic class

余生长醉 提交于 2020-06-22 11:42:25
问题 I'm using the WPF Extended Toolkit ( http://wpftoolkit.codeplex.com/ ). It has a nice NumericUpDown control that I'd like to use, but internally it uses doubles - which means it uses double.MinValue and double.MaxValue. I'd like to use the same control, but I need a generic version - for ints it needs to use int.MaxValue/MinValue, for floats float.MaxValue/MinValue, etc. (I think you get the idea :)) So I though about copying the NumericUpDown to a GNumericUpDown, where T would ofcourse be

Why is the generic value N not inferred from arguments in this case?

断了今生、忘了曾经 提交于 2020-06-17 13:19:08
问题 This question: TypeScript: Require that two arrays be the same length? Asks how to create a function that requires two arrays of the same length. Here's my attempt at a solution. type ArrayOfFixedLength<T extends any, N extends number> = readonly T[] & { length: N }; const a1: ArrayOfFixedLength<number, 2> = [1] as const; //expected error const a2: ArrayOfFixedLength<number, 2> = [1, 2] as const; function myFunction<N extends number>(array1: ArrayOfFixedLength<any, N >, array2:

Is there a way to generically quickly insert (log(n)) an item into any IList<T>

蓝咒 提交于 2020-06-17 12:55:05
问题 In WPF, I want to keep my ObservableCollection sorted. Items are added randomly and not in batch. I do not want to sort the entire IList each time. I want to insert at the proper place on each insert. Is there a way to generically insert quickly (log(n)) an item into any IList of T. Does anyone wrote the code for it? Note: Yes, the list should already be sorted before calling this method. Note2: Sometimes you have to use an IList and can't replace it with a SortedList and do not want to

How do I use java 8's stream collect from scala 2.11?

我怕爱的太早我们不能终老 提交于 2020-06-17 00:10:24
问题 I have this piece of code: import java.util.stream._ import java.util.function._ final case class AbcTest(value: String) def funToFunction[InT, OutT](fun: InT => OutT): Function[InT, OutT] = new Function[InT, OutT] { override def apply(t: InT): OutT = fun(t) } def main(args: Array[String]): Unit = { Stream.of("a", "b", "c") .map[AbcTest](funToFunction((v: String) => AbcTest(v))) .collect(Collectors.toList()) } And it fails with this error message: Error:(43, 27) type mismatch; found : java

How to return the instance of first-class module's nested type from a function?

∥☆過路亽.° 提交于 2020-06-16 18:36:35
问题 Context: I am trying to implement something like OOP observable pattern in OCaml with using first-class modules. I have a project with a list of modules and want to extend them with observation without changing. To minimize code duplication I created Subject module and plan to use it as a part of the common way (in the project context) for this extending. I declared three module types: OBSERVER: module type OBSERVER = sig type event type t val send : event -> t -> t end OBSERVABLE: module