generics

Length function for generic lists

ⅰ亾dé卋堺 提交于 2021-02-10 05:49:46
问题 This post shows how to axiomatise a length function for Z3's built-in lists. However, the function is sort-specific (here Int) and not applicable to lists of bools or custom sorts. ; declare len as an uninterpreted function (declare-fun len ((List Int)) Int) ; assert defining equations for len as an axiom (assert (forall ((xs (List Int))) (ite (= nil xs) (= 0 (len xs)) (= (+ 1 (len (tail xs))) (len xs))))) What would be the smartest way of encoding sort-generic list functions? (If I remember

Initializing Generic Variables in Java?

假装没事ソ 提交于 2021-02-10 05:03:21
问题 I'm having trouble working with generics. I have a method as public void push (T element) Now what I'm having trouble understanding is how to create a generic variable so that I can pass it into that method. I know that the generic will always be a number, but I'm not getting how I should do that. Would it have to be something like T number = 5 And then would I be able to pass that into the push method? I'm quite confused. Thoughts guys? 回答1: You stated that T was a Number public class

Initializing Generic Variables in Java?

无人久伴 提交于 2021-02-10 05:01:34
问题 I'm having trouble working with generics. I have a method as public void push (T element) Now what I'm having trouble understanding is how to create a generic variable so that I can pass it into that method. I know that the generic will always be a number, but I'm not getting how I should do that. Would it have to be something like T number = 5 And then would I be able to pass that into the push method? I'm quite confused. Thoughts guys? 回答1: You stated that T was a Number public class

When I override the “put(K key, V value)” in a TreeMap, how can I change “value”?

99封情书 提交于 2021-02-10 05:01:16
问题 I extend a TreeMap, override "put()", and do something equivalent to: public class MyMap<K, Integer> extends TreeMap<K, Integer> { @Override public Integer put(K key, Integer value) throws ClassCastException, NullPointerException { java.lang.Integer newValue = java.lang.Integer.valueOf(123); super.put(key, newValue); // <--- error message here return newValue; } } error message: no suitable method found for put(K, java.lang.Integer)... java.lang.Integer cannot be converted Integer. I know it

When I override the “put(K key, V value)” in a TreeMap, how can I change “value”?

谁都会走 提交于 2021-02-10 04:59:05
问题 I extend a TreeMap, override "put()", and do something equivalent to: public class MyMap<K, Integer> extends TreeMap<K, Integer> { @Override public Integer put(K key, Integer value) throws ClassCastException, NullPointerException { java.lang.Integer newValue = java.lang.Integer.valueOf(123); super.put(key, newValue); // <--- error message here return newValue; } } error message: no suitable method found for put(K, java.lang.Integer)... java.lang.Integer cannot be converted Integer. I know it

How can a macro define a valid global name based on the type passed to it?

守給你的承諾、 提交于 2021-02-10 04:36:05
问题 I believe the title is self-explanatory, but here's an example to illustrate what I'm trying to accomplish: #define PASTE2(_0, _1) _0 ## _1 #define DEFINE_OPS_FOR_TYPE(TYPE) \ int PASTE2(do_something_with_, TYPE)(void) { \ /* do_something_with_<TYPE> */ \ } Everything works fine for char , int , and single-worded types, but when it comes to unsigned types, or others that have multiple keywords, using token pasting ( a ## b ) does not generate a valid name due to the whitespace (e.g.: do

Generic list of actions/funcs

社会主义新天地 提交于 2021-02-10 04:14:44
问题 I'm wondering if its possible to create some kind of generic list of actions/funcs, each with different in/out params. The reason I need this is I have an executer who's job is getting data from an API, each of the methods in that executer goes to a different path in that API, and I want to be able to schedule those requests so I won't overload that API (they will just block me if I pass their threshold of requests). So each time a method in that executer is called, I will add that method and

Generic list of actions/funcs

允我心安 提交于 2021-02-10 04:10:22
问题 I'm wondering if its possible to create some kind of generic list of actions/funcs, each with different in/out params. The reason I need this is I have an executer who's job is getting data from an API, each of the methods in that executer goes to a different path in that API, and I want to be able to schedule those requests so I won't overload that API (they will just block me if I pass their threshold of requests). So each time a method in that executer is called, I will add that method and

Generic list of actions/funcs

本秂侑毒 提交于 2021-02-10 04:09:21
问题 I'm wondering if its possible to create some kind of generic list of actions/funcs, each with different in/out params. The reason I need this is I have an executer who's job is getting data from an API, each of the methods in that executer goes to a different path in that API, and I want to be able to schedule those requests so I won't overload that API (they will just block me if I pass their threshold of requests). So each time a method in that executer is called, I will add that method and

Narrow inferred type when function has explicit return

隐身守侯 提交于 2021-02-09 10:55:55
问题 Look at the following code: type Shape = null | string | string[] | { [key: string]: string | string[] } interface ICfg<InShape extends Shape, OutShape extends Shape> { shapes?: readonly [InShape, OutShape] handle?(x: NonNullable<this["shapes"]>[0]): NonNullable<this["shapes"]>[1] } function apply<InShape extends Shape, OutShape extends Shape>(cfg: () => ICfg<InShape, OutShape>) { return cfg() } const shape = { type: "abc", date: "qwe", } var x = apply(() => ({ shapes: [shape, shape], handle: