variable-assignment

Auto-align “=” in assignments

依然范特西╮ 提交于 2019-11-27 22:25:39
How do one convert a block of variable assignments, e.g.: private final String s1 = "10011"; private final String s2 = "01100"; private final String ones = "11111"; private final String zeros = "00000"; To a straightened format where all = signs are aligned to one space after the longest left-hand side, e.g.: private final String s1 = "10011"; private final String s2 = "01100"; private final String ones = "11111"; private final String zeros = "00000"; Preferences → Java → Code Style → Formatter → goto Edit and check the Align fields in columns : Tibi If you want to be able to align assignments

Is there a name for “this” in Java?

这一生的挚爱 提交于 2019-11-27 21:32:58
问题 Eclipse will give an error, "The left-hand side of an assignment must be a variable", when I try something like: public class Thing{ String a1; int a2; public void meth(){ Thing A = new Thing(); this = A; } } I had to assign each variable ( this.a1 = A.a1; this.a2 = A.a2; ) as a work around. Are there other ways to do this without going through each variable field? And if this is not a variable what is it called? 回答1: this is a pseudo-variable that points to the current instance of the object

Set the variable result, from query

邮差的信 提交于 2019-11-27 20:32:11
When I create the saved procedure, i can create some variable yes? for example: CREATE PROCEDURE `some_proc` () BEGIN DECLARE some_var INT; SET some_var = 3; .... QUESTION: but how to set variable result from the query, that is how to make some like this: DECLARE some_var INT; SET some_var = SELECT COUNT(*) FROM mytable ; ? Roland Bouman There are multiple ways to do this. You can use a subquery: SET some_var = (SELECT COUNT(*) FROM mytable); (like your original, just add parenthesis around the query) or use the SELECT INTO syntax to assign multiple values: SELECT COUNT(*), MAX(col) INTO some

assigning class variable as default value to class method argument

雨燕双飞 提交于 2019-11-27 20:22:44
I would like to build a method inside a class with default values arguments taken from this class. In general I do filtering on some data. Inside my class I have a method where normally I pass vector of data. Sometimes I don't have the vector and I take simulated data. Every time I do not pass a particular vector I would like to take simulated data by default. I thought it should be an easy construction where inside my method definition I say a=self.vector . But for some reason I have an error NameError: name 'self' is not defined . The simplified construction is: class baseClass(object): #

Why does foo = filter(…) return a <filter object>, not a list? [duplicate]

心已入冬 提交于 2019-11-27 20:22:02
This question already has an answer here: Filters in Python3 [duplicate] 2 answers Working in Python IDLE 3.5.0 shell. From my understanding of the builtin "filter" function it returns either a list, tuple, or string, depending on what you pass into it. So, why does the first assignment below work, but not the second (the '>>>'s are just the interactive Python prompts) >>> def greetings(): return "hello" >>> hesaid = greetings() >>> print(hesaid) hello >>> >>> shesaid = filter(greetings(), ["hello", "goodbye"]) >>> print(shesaid) <filter object at 0x02B8E410> Have a look at the python

How to make a copy of a 2D array in Python? [duplicate]

邮差的信 提交于 2019-11-27 20:21:17
问题 This question already has answers here : Copying nested lists in Python (3 answers) How to clone or copy a list? (16 answers) Closed last year . X is a 2D array. I want to have a new variable Y that which has the same value as the array X . Moreover, any further manipulations with Y should not influence the value of the X. It seems to me so natural to use y = x . But it does not work with arrays. If I do it this way and then changes y, the x will be changed too. I found out that the problem

Multiple variable assignment in Swift

感情迁移 提交于 2019-11-27 20:01:39
How do I assign multiple variables in one line using Swift? var blah = 0 var blah2 = 2 blah = blah2 = 3 // Doesn't work??? Matt Gibson You don't. This is a language feature to prevent the standard unwanted side-effect of assignment returning a value, as described in the Swift book : Unlike the assignment operator in C and Objective-C, the assignment operator in Swift does not itself return a value. The following statement is not valid: if x = y { // this is not valid, because x = y does not return a value } This feature prevents the assignment operator ( = ) from being used by accident when

What does `let 5 = 10` do? Is it not an assignment operation?

走远了吗. 提交于 2019-11-27 19:59:57
If I say let 5 = 10 , why does 5 + 1 return 6 instead of 11 ? When you say let 5 = 10 it's not a redefinition of 5, it's a pattern matching, the same which occurs when you say foo 5 = undefined ... foo 10 ... The pattern simply fails if it's ever matched. In let-expressions the match is lazy. This means the match is only being done when a variable bound by it is evaluated. This allows us to write things like let foo = undefined in 10 In your expression, no variable is bound, so the pattern is never matched. Arguably such patterns with no variables make no sense in let-bindings and should be

Return value of assignment operator in concurrent code

≡放荡痞女 提交于 2019-11-27 19:38:53
Given the following class: class Foo { public volatile int number; public int method1() { int ret = number = 1; return ret; } public int method2() { int ret = number = 2; return ret; } } and given multiple threads calling method1() and method2() concurrently on the same Foo instance, can a call to method1() ever return anything other than 1? The JLS 15.26 specifies: There are 12 assignment operators; all are syntactically right-associative (they group right-to-left). Thus, a=b=c means a=(b=c), which assigns the value of c to b and then assigns the value of b to a. Ted Hopp's answer shows that

Is it possible to have tuple assignment to variables in Scala? [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-11-27 19:35:40
Possible Duplicate: Tuple parameter declaration and assignment oddity In Scala, one can do multiple-variable assignment to tuples via: val (a, b) = (1, 2) But a similar syntax for assignment to variables doesn't appear to work. For example I'd like to do this: var (c, d) = (3, 4) (c, d) = (5, 6) I'd like to reuse c and d in multiple-variable assignment. Is this possible? This isn't simply "multiple variable assignment", it's fully-featured pattern matching! So the following are all valid: val (a, b) = (1, 2) val Array(a, b) = Array(1, 2) val h :: t = List(1, 2) val List(a, Some(b)) = List(1,