java - How to set Value in Global Variable? -


i have declared variable on top after import

string sk5; 

putted value in sk5

sk5 = s.substring(s.lastindexof("-")+1).replace("]", "");          system.out.println("checking sk5->"+sk5); 

it printing value well, when using variable in other function prints null. please suggest me how solve this.

i assume want define class variable, should use

public static string sk5; 

but defining public static variable not final bad code style. if want use class variables in other classes, should implement getter-method like

private static string sk5;  public static string getsk5(){    return sk5; } 

and still static variable not best. try check singleton instead, depending on our usecase make sence

from point of view best define

private string sk5;  public string getsk5(){    return sk5; } 

so can call

testclass s = new testclass(); string t = s.getsk5(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -