Search Results

Search found 2715 results on 109 pages for 'lazy initialization'.

Page 24/109 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • Reference variable to an object instantiated/initialized in another class in Java

    - by Alex
    The reason I'm asking is because I'm getting NullPointerException. I now this is very easy but I'm pretty new programming and find this a bit confusing. So say I have initialized an object in a class and want to access that same object from another class. Like now for instance I'm working on a small Chess game, in my model Game class I have an instance of Board, an object. Board, in turn, has an array of Squares. Square[][]. Game has board, board has Square[][]. Now if I want to access the Square[][] through the object board (in Game) of type Board. Do I just declare a variable with the same name and type or do I have to initialize it again? Board board OR Board board = new Board(); Note, I have already initialized board in the class Game so if I do it again, won't they be two totally different Board objects?

    Read the article

  • Python - Create a list with initial capacity

    - by Claudiu
    Code like this often happens: l = [] while foo: #baz l.append(bar) #qux This is really slow if you're about to append thousands of elements to your list, as the list will have to constantly be re-initialized to grow. (I understand that lists aren't just wrappers around some array-type-thing, but something more complicated. I think this still applies, though; let me know if not). In Java, you can create an ArrayList with an initial capacity. If you have some idea how big your list will be, this will be a lot more efficient. I understand that code like this can often be re-factored into a list comprehension. If the for/while loop is very complicated, though, this is unfeasible. Is there any equivalent for us python programmers?

    Read the article

  • Java: how to initialize String[]?

    - by Heoa
    Error % javac StringTest.java StringTest.java:4: variable errorSoon might not have been initialized errorSoon[0] = "Error, why?"; Code public class StringTest { public static void main(String[] args) { String[] errorSoon; errorSoon[0] = "Error, why?"; } }

    Read the article

  • if (self = [super init]) vs. if ((self = [super init]))

    - by JOM
    Was just doing a code review and started to wonder: I thought if (self = [super init]) checks whether assigning return value of [super init] to variable self was successful or not (value of operation). Thus (self = nil) would actually be TRUE. I thought if ((self = [super init])) checks what is the value of self after assignment (value of variable). Thus ((self = nil)) would be FALSE. Which one is the correct way to use when initializing your own classes? Apple documentation uses the former one (for example here), which style I'm actually using now.

    Read the article

  • C# assign values of array to separate variables in one line

    - by Sarah Vessels
    Can I assign each value in an array to separate variables in one line in C#? Here's an example in Ruby code of what I want: irb(main):001:0> str1, str2 = ["hey", "now"] => ["hey", "now"] irb(main):002:0> str1 => "hey" irb(main):003:0> str2 => "now" I'm not sure if what I'm wanting is possible in C#. Edit: for those suggesting I just assign the strings "hey" and "now" to variables, that's not what I want. Imagine the following: irb(main):004:0> val1, val2 = get_two_values() => ["hey", "now"] irb(main):005:0> val1 => "hey" irb(main):006:0> val2 => "now" Now the fact that the method get_two_values returned strings "hey" and "now" is arbitrary. In fact it could return any two values, they don't even have to be strings.

    Read the article

  • Is possible to initialize an object in javascript in this way?

    - by Kucebe
    I'd like to initialize an object in javascript calling directly a method that belongs to it: var obj = (function(){ return{ init: function(){ console.log("initialized!"); }, uninit: function(x){ console.log("uninitialized!"); } }; }).init(); //later obj.uninit(); obj.init(); This specific example doesn't work, is there something similar?

    Read the article

  • How is a constructor executed?

    - by simion
    I am doing some reviison from the lecture slides and it says a constructor is executed in the following way; If the constructor starts with this, recursively execute the indicated constructor, then go to step 4. Invoke the explicitly or implicitly indicated superclass constructor (unless this class is java.lang.Object) Initialise the fields of the object in the order in which they were declared in this class Execute the rest of the body of this constructor. What i dont undertsand is that, a constructor can never "start" with this, because even if it forms no class heirarchy/relationship then super() is inserted by default. How would this fit in with the description above? Thanks

    Read the article

  • Is it bad practice to initialize a variable to a dummy value?

    - by froadie
    This question is a result of the answers to this question that I just asked. It was claimed that this code is "ugly" because it initializes a variable to a value that will never be read: String tempName = null; try{ tempName = buildFileName(); } catch(Exception e){ ... System.exit(1); } FILE_NAME = tempName; Is this indeed bad practice? Should one avoid initializing variables to dummy values that will never actually be used? (EDIT - And what about initializing a String variable to "" before a loop that will concatenate values to the String...? Or is this in a separate category? e.g. String whatever = ""; for(String str : someCollection){ whatever += str; } )

    Read the article

  • Is new int[10]() valid c++?

    - by Naveen
    While trying to answer this question I found that the code int* p = new int[10](); compiles fine with VC9 compiler and initializes the integers to 0. So my questions are: First of all is this valid C++ or is it a microsoft extension? Is it guaranteed to initialize all the elements of the array? Also, is there any difference if I do new int; or new int();? Does the latter guarantee to initialize the variable?

    Read the article

  • C# Strange Behavior

    - by Betamoo
    I have a custom struct : struct A { public int y; } a custom class with empty constuctor: class B { public A a; public B() { } } and here is the main: static void Main(string[] args) { B b = new B(); b.a.y = 5;//No runtime errors! Console.WriteLine(b.a.y); } When I run the above program, it does not give me any errors, although I did not initialize struct A in class B constructor..'a=new A();'

    Read the article

  • Is Java class initialized by the thread which use it for the first time?

    - by oo_olo_oo
    Lets assume following classes definition: public class A { public final static String SOME_VALUE; static { SOME_VALUE = "some.value"; } } public class B { private final String value = A.SOME_VALUE; } Assuming that the class A hasn't been loaded yet, what does happen when object of the class B is instantiated by some thread T? The class A has to be loaded and instantiated first. But my question is: if it's done in context of the thread T, or rather in context of some other (special) "classloader" thread?

    Read the article

  • Unexpected output on initializing array by using both `element-by-element` & `designated` technique

    - by haccks
    C99 provides a feature to initialize arrays by using both element-by-element & designated method together as: int a[] = {2,1,[3] = 5,[5] = 9,6,[8] = 4}; On running the code: #include <stdio.h> int main() { int a[] = {2,1,[3] = 5,[0] = 9,4,[6] = 25}; for(int i = 0; i < sizeof(a)/sizeof(a[0]); i++) printf("%d ",a[i]); return 0; } (Note that Element 0 is initialized to 2 and then again initialised by designator [0] to 9) I was expecting that element 0(which is 2) will be replaced by 9(as designator [0] = 9) and hence o/p will become 9 1 0 5 4 0 25 Unfortunately I was wrong as o/p came; 9 4 0 5 0 0 25 Any explanation for unexpected o/p?

    Read the article

  • Prevent breaking of specified part of paragraph

    - by AntonAL
    For example, we have a paragraph: Quick brown fox jumps over the lazy dog How can i prevent breaking the part "the lazy" ? I means, that this string will be incorrect in my formatting: Quick brown fox jumps over the lazy dog But this one is correct: Quick brown fox jumps over the lazy dog My text is large and hitting "Shift+Enter" at some placed is ugly, because everything will crash, when text size will be changed ... Selecting the part "the lazy", right-click - "Prevent breaking" does not works Help!

    Read the article

  • From the Coalface - 3 - Work as hard as you can to be as lazy as you can!

    - by TATWORTH
    The saga of the Change Log A recent conversation reminded me of the need for change logs within a database, to record when various change scripts were run. Creating such the required table is simple. A typical table for this consists of: Id - identity Integer primary key ChangeFileName - NVARCHAR(128) to hold the name of the file run. DateAdded - DateTime non-null with default value of getutcdate() Purpose - NVARCHAR(128) Rerunnable - Bit non-null default 0. By good design of the table only two data values normally need to be supplied. Two stored procedures, one for inserting data and one to list in reverse sequence the log complete the database essentials. The complete implementation can be found in the CommonData solution at http://CommonData.CodePlex.Com By including a call the add Change Log stored procedure, each script can log its name and purpose for posterity. The scripts that were applied to say the UAT system and their sequence of application can be readily identified for running on the Live system. Formatting XML XML is often produced as one continous string with no embedded CR/LF. To get it into human readable form, open it in visual studio, swap to another tab and back and click the format document button. The XML will then be nicely formatted!

    Read the article

  • From the Coalface - 2 - Work as hard as you can to be as lazy as you can

    - by TATWORTH
    On one project, the standard build involved building the database from scratch producing a build log that was about 100,000 lines long.  Manually paging throught this log took hours and it was very easy to miss any errors. The solution was to write a filter that read the log file and output a summary file with each output line pepended with the line number in the original file. Sucessive iterations eliminated more noise lines. Diagnostic displays required escaping. The final output was just a few hundred lines long and the errors were easy to spot. The filter program took less time to to write than one manual pass reading the log file.  The utility digested the log file in about 1 second. Now database build errors could be identified quickly instead of after hours of manual examination or lengthy system testing. A few minutes consideration of the task led to a tremendous improvement in quality.

    Read the article

  • Any difference between lazy loading Javascript files vs. placing just before </body>

    - by mhr
    Looked around, couldn't find this specific question discussed. Pretty sure the difference is negligible, just curious as to your thoughts. Scenario: All Javascript that doesn't need to be loaded before page render has been placed just before the closing </body> tag. Are there any benefits or detriments to lazy loading these instead through some Javascript code in the head that executes when the DOM load/ready event is fired? Let's say that this only concerns downloading one entire .js file full of functions and not lazy loading several individual files as needed upon usage. Hope that's clear, thanks.

    Read the article

  • 10.10 - Error compiling kernel in iw_ndis.c

    - by chris
    I just wanted to compile a kernel (as described here), but I got this error: ubuntu/ndiswrapper/iw_ndis.c:1966: error: unknown field ‘num_private’ specified in initializer ubuntu/ndiswrapper/iw_ndis.c:1966: warning: initialization makes pointer from integer without a cast ubuntu/ndiswrapper/iw_ndis.c:1967: error: unknown field ‘num_private_args’ specified in initializer ubuntu/ndiswrapper/iw_ndis.c:1967: warning: excess elements in struct initializer ubuntu/ndiswrapper/iw_ndis.c:1967: warning: (near initialization for ‘ndis_handler_def’) ubuntu/ndiswrapper/iw_ndis.c:1970: error: unknown field ‘private’ specified in initializer ubuntu/ndiswrapper/iw_ndis.c:1970: warning: initialization makes integer from pointer without a cast ubuntu/ndiswrapper/iw_ndis.c:1970: error: initializer element is not computable at load time ubuntu/ndiswrapper/iw_ndis.c:1970: error: (near initialization for ‘ndis_handler_def.num_standard’) ubuntu/ndiswrapper/iw_ndis.c:1971: error: unknown field ‘private_args’ specified in initializer ubuntu/ndiswrapper/iw_ndis.c:1971: warning: initialization from incompatible pointer type Can anyone tell me what it means? Googling just came up with a result here on this site, where there was no answer, so maybe now someone knows.

    Read the article

  • How should I implement lazy session creation in PHP?

    - by Adam Franco
    By default, PHP's session handling mechanisms set a session cookie header and store a session even if there is no data in the session. If no data is set in the session then I don't want a Set-Cookie header sent to the client in the response and I don't want an empty session record stored on the server. If data is added to $_SESSION, then the normal behavior should continue. My goal is to implement lazy session creation behavior of the sort that Drupal 7 and Pressflow where no session is stored (or session cookie header sent) unless data is added to the $_SESSION array during application execution. The point of this behavior is to allow reverse proxies such as Varnish to cache and serve anonymous traffic while letting authenticated requests pass through to Apache/PHP. Varnish (or another proxy-server) is configured to pass through any requests without cookies, assuming correctly that if a cookie exists then the request is for a particular client. I have ported the session handling code from Pressflow that uses session_set_save_handler() and overrides the implementation of session_write() to check for data in the $_SESSION array before saving and will write this up as library and add an answer here if this is the best/only route to take. My Question: While I can implement a fully custom session_set_save_handler() system, is there an easier way to get this lazy session creation behavior in a relatively generic way that would be transparent to most applications?

    Read the article

  • Sonicwall SSL VPN Login : I need help with a NetExtender initialization error.

    - by jacke672
    I receive the error message: "Server is busy now, please try it later!" after logging into our Sonicwall successfully and attempting to initialize NetExtender for the "virtual office" function. It was set up yesterday and I am able to log in without any issues, but I keep getting hung up on the installation and/or initialization of NetExtender. I have attempted to connect remotely on XP and 7 using both FireFox and IE. I am using a Sonicwall NSA-240 with load balancing active (1 ISP and 2 different connections)- I have tried turning off load balancing and disabling the secondary connection but still receive the same error. I've been in contact with SonicWall support but I haven't heard from them as of yet so I'm asking the Server Fault community in the meantime... Does anyone have any ideas as per what could be the issue? Thanks -Jack

    Read the article

  • STS 2.5.2 showing error error occurred during initialization of vm could not reserve enough space for object heap eclipse

    - by user1460079
    I am using STS2.5.5 with jdk 1.6 in my system with 32 BIT winx Xp it was working fine for few HRs when i installed it for the first time, after that when i restart STS it started showing exception Failed Initialize when i start the TC it throws hte exception error occurred during initialization of vm could not reserve enough space for object heap eclipse It is working fine in another system with same config, to resolve this if i delete STS and reinstall STS it works fine but again throws same error if i close STS and open it can anybody help me, i am also not able to change the size in my sts.ini if i increase memory and start STS then it will not start.

    Read the article

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >