local-variables

Scope of final local variable in java

对着背影说爱祢 提交于 2019-12-19 17:47:23
问题 Method-Local inner class cannot access local variables because the instance of the method-local inner class may still alive after the method is over. But local variables will vanish once the local method is over. I learned that method-local inner class can access final local variable, does this mean final local variable still alive after the method is over? 回答1: Sort of. Java anonymous inner classes act like "closures," that is, they "close" around the current local state. However, Java only

“array initializer needs an explicit target-type” - why?

本秂侑毒 提交于 2019-12-19 05:03:15
问题 Following JEP 286: Local-Variable Type Inference description I am wondering, what the reason is for introducing such a restriction, as: Main.java:199: error: cannot infer type for local variable k var k = { 1 , 2 }; ^ (array initializer needs an explicit target-type) So for me logically it should be: var k = {1, 2}; // Infers int[] var l = {1, 2L, 3}; // Infers long[] Because Java compiler can already infer properly the type of an array: void decide() { arr(1, 2, 3); // call void arr(int ..

Using function arguments as local variables

我的未来我决定 提交于 2019-12-18 12:15:26
问题 Something like this (yes, this doesn't deal with some edge cases - that's not the point): int CountDigits(int num) { int count = 1; while (num >= 10) { count++; num /= 10; } return count; } What's your opinion about this? That is, using function arguments as local variables. Both are placed on the stack, and pretty much identical performance wise, I'm wondering about the best-practices aspects of this. I feel like an idiot when I add an additional and quite redundant line to that function

Use of final local variables in java [duplicate]

淺唱寂寞╮ 提交于 2019-12-17 23:16:42
问题 This question already has answers here : Why would one mark local variables and method parameters as “final” in Java? [closed] (12 answers) Closed 3 years ago . I was wondering is there any usability of using final local variables. Variables are not overridden anyway when inheritance comes into picture. For example a simple code as below public static void main(String args[]) { final String data = "Hello World!"; System.out.println(data); } The example is quite simple one and may not be a

how refer to a local variable share same name of a global variable in C? [duplicate]

家住魔仙堡 提交于 2019-12-17 18:56:40
问题 This question already has answers here : How to print value of global variable and local variable having same name? (4 answers) Closed 2 years ago . for example #include<stdio.h> int foo = 100; int bar() { int foo; /* local foo = global foo, how to implemented? */ return 0; } int main() { int result = bar(); return 0; } I think in the function bar, calling foo directly will just get the global foo. How can I refer the local foo? I know in C++, there is this pointer. However, does C has

Any way to modify locals dictionary?

好久不见. 提交于 2019-12-17 02:24:45
问题 locals is a built in function that returns a dictionary of local values. The documentation says: Warning The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. Unfortunately, exec has the same problem in Python 3.0. Is there any way round this? Use Case Consider: @depends("a", "b", "c", "d", "e", "f") def test(): put_into_locals(test.dependencies) depends stores the strings provided in its arguments in a list test

“life-time” of string literal in C

瘦欲@ 提交于 2019-12-16 22:12:10
问题 Wouldn't the pointer returned by the following function inaccessible? char *foo( int rc ) { switch (rc) { case 1: return("one"); case 2: return("two"); default: return("whatever"); } } So the lifetime of a local variable in C/C++ is practically only within the function, right? Which means, after char* foo(int) terminates, the pointer it returns no longer means anything? I'm a bit confused about lifetime of local var. Could anyone give me a good clarification? 回答1: Yes, lifetime of an local

How to access Local variables of functions when the function call has finished in python?

陌路散爱 提交于 2019-12-13 08:26:56
问题 I found on the net that local variables of functions can't be accessed from outside when the function call has finished.I try to execute the program but it throws an error that variable is not defined. My code is xyz=list() n=0 def length(g): i=0 n=g v=input("no of") while i<v: c=input("Enter the 1st dimension:") j=input("Enter the 2nd dimension:") i=i+1 xyz.append(c) xyz.append(j) return c return j return n def prod(): global c for i in xyz: if n<c and n<j: print "Upload another" elif n==c

Add a variable to the stack in x86 assembly [closed]

删除回忆录丶 提交于 2019-12-13 04:46:17
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I wonder, how to set a local variable in ASM's procedure ? thanks!! 回答1: If you want to store a variable on the stack, you need to reserve space for it, this is generally done with the SUB ESP,xxx sequence, where

Declare Locally or Globally in Delphi?

醉酒当歌 提交于 2019-12-13 04:25:05
问题 I have a procedure my program calls tens of thousands of times that uses a generic structure like this: procedure PrintIndiEntry(JumpID: string); type TPeopleIncluded = record IndiPtr: pointer; Relationship: string; end; var PeopleIncluded: TList<TPeopleIncluded>; PI: TPeopleIncluded; begin { PrintIndiEntry } PeopleIncluded := TList<TPeopleIncluded>.Create; { A loop here that determines a small number (up to 100) people to process } while ... do begin PI.IndiPtr := ...; PI.Relationship := ...