literals

Typescript - Why can't this string literal type be inferred?

余生长醉 提交于 2019-12-07 03:14:48
问题 The following snippet does not pass the type check: type TaskType = 'SIMPLE' | 'COMPLEX' interface TaskDefinition { name: string, task: string, taskType: TaskType }; const test: TaskDefinition = { name: '', task: '', taskType: 'SIMPLE' // This is fine }; const tasks : TaskDefinition[] = ["apples", "pears"].map(i => { return { name: i, task: i, taskType: 'SIMPLE' // This one is not }; }) { name: string; task: string; taskType: string; }[] is not assignable to type TaskDefinition []. Try it It

How to return a string literal from a function

爷,独闯天下 提交于 2019-12-07 00:53:31
问题 I am always confused about return a string literal or a string from a function. I was told that there might be memory leak because you don't know when the memory will be deleted? For example, in the code below, how to implement foo() so as to make the output of the code is "Hello World"? void foo ( ) // you can add parameters here. { } int main () { char *c; foo ( ); printf ("%s",c); return 0; } Also, if the return type of foo() is not void, but you can return char* , what should it be? 回答1:

Difference between modes of literal control

随声附和 提交于 2019-12-06 23:54:11
问题 What is the difference between the passthrough and Transform modes of literal control? Could you post an example, too? 回答1: There are different Literal Modes Literal.Mode PassThrough : The contents of the control are not modified. Encode : The contents of the control are converted to an HTML-encoded string. Transform : Unsupported markup-language elements are removed from the contents of the control. If the Literal control is rendered on a browser that supports HTML or XHTML, the control's

How do I write a map literal in C++11? [duplicate]

孤人 提交于 2019-12-06 19:36:50
问题 This question already has answers here : Initializing a static std::map<int, int> in C++ (11 answers) Closed 6 years ago . In Python, I can write a map literal like this: mymap = {"one" : 1, "two" : 2, "three" : 3} How can I do the equivalent in C++11? 回答1: You can actually do this: std::map<std::string, int> mymap = {{"one", 1}, {"two", 2}, {"three", 3}}; What is actually happening here is that std::map stores an std::pair of the key value types, in this case std::pair<const std::string,int>

Creating a list with >255 elements

梦想与她 提交于 2019-12-06 19:36:44
问题 Ok, so I'm writing some python code (I don't write python much, I'm more used to java and C). Anyway, so I have collection of integer literals I need to store. (Ideally >10,000 of them, currently I've only got 1000 of them) I would have liked to be accessing the literals by file IO, or by accessing there source API, but that is disallowed. And not ontopic anyway. So I have the literals put into a list: src=list(0,1,2,2,2,0,1,2,... ,2,1,2,1,1,0,2,1) #some code that uses the src But when I try

Passing Array to Python Spark Lit Function

♀尐吖头ヾ 提交于 2019-12-06 17:57:14
问题 Let's say I have a numpy array a that contains the numbers 1-10. So a is [1 2 3 4 5 6 7 8 9 10]. Now, I also have a Python Spark dataframe to which I want to add my numpy array a. I figure that a column of literals will do the job. So I do the following: df = df.withColumn("NewColumn", F.lit(a)) This doesn't work. The error is "Unsupported literal type class java.util.ArrayList". Now, if I try just one element of the array, as follows, it works. df = df.withColumn("NewColumn", F.lit(a[0])) Is

Why does 1.__add__(2) not work out? [duplicate]

别等时光非礼了梦想. 提交于 2019-12-06 17:27:56
问题 This question already exists : Closed 7 years ago . Possible Duplicate: accessing a python int literals methods In Python, everything is an object . But then again, why doesn't the following snippet work? 1.__add__(2) However, this does work: n = 1 n.__add__(2) What is the difference between n and 1 ? Isn't it a design failure that it doesn't work? For instance, it does work with string literals as well. "one".__add__("two") For comparison, it works well on other purely object oriented

Want to access literal value into javascript

吃可爱长大的小学妹 提交于 2019-12-06 15:28:00
I have got a literal control on page (with some data on it). i want to access it in javascript and want to put some text on it. please tell me how can i access literal control in JavaScript. I was trying with following code- <asp:Literal ID="lblPerInstanceListing" runat="server"></asp:Literal> Javascript: var value= document.getElementById('<%=lblPerInstanceListing.ClientID %>') I am getting null value return by this. An ASP.NET Literal control does not by itself insert any HTML into a webpage. Your Literal control is a placeholder for text or HTML you will set in your code behind. You should

Why does instanceof return false for some literals?

こ雲淡風輕ζ 提交于 2019-12-06 13:36:35
"foo" instanceof String //=> false "foo" instanceof Object //=> false true instanceof Boolean //=> false true instanceof Object //=> false false instanceof Boolean //=> false false instanceof Object //=> false // the tests against Object really don't make sense Array literals and Object literals match... [0,1] instanceof Array //=> true {0:1} instanceof Object //=> true Why don't all of them? Or, why don't they all not ? And, what are they an instance of, then? It's the same in FF3, IE7, Opera, and Chrome. So, at least it's consistent. Missed a few. 12.21 instanceof Number //=> false /foo/

Unexpected int/Integer behavior when number starts by 0

北战南征 提交于 2019-12-06 13:18:56
I can't understand why this is not printing the expected value (400300) when I put extra zeros in front of the number: System.out.println(new Integer(0400300)); // prints 131264 System.out.println(0400300); // prints 131264 If I put one or more zeros in front of the number, the expected value is not printed. // JUnit test does not pass: assertTrue(0400300 == 400300); // returns false!? Adding 0 to the front made the number an Octal literal . So: 0400300 = 3 * 8 ^ 2 + 4 * 8 ^ 5 = 131264 See JLS for the relevant sections. Quote: An octal numeral consists of an ASCII digit 0 followed by one or