Calling a Classes constrictor explicitly with out editing the Class
Hi All,
I am looking for a way to call the a Classes static constructor of a class so that the static fields get initialized. Here is some pseudo code to illustrate
class Singleton {
private static instance = new Singleton();
private Map map = new HashMap();
boolean obtainedKey = false;
private Singleton() {
//populate map code
public Singleton getInstance() {
return instance;
public Object getVal(String key) {
obtainedKey = true;
return map.get(key);
public getObtainedKey() {
return obtainedKey;
class MyClass {
static Singleton sing = Singleton.getInstance();
static Object objVal = sing getVal.get("key");
public static void main(String [] args) {
Singleton singMain = Singleton.getInstance();
MyClass.*SOME_METHOD_ALREADY_IN_JAVA*;
assert(singMain.getObtainedKey() == true);
} One solution is to add a method ;
static void init() {}; to the class MyClass and then to call this method,
However I would like to find a method somewhere in the java library so I don't have to write a init method.
I think you really should re-think your architecture if it depends on such strange loops (and personally I've had very bad experiences with static initializer blocks, especially those that can fail).
But curiousity got the better of me and I dug into the JVM spec. In �2.11 (http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#32316) it says
Any static initializers declared in a class are executed when the class is initialized (�2.17.4) and, together with any field initializers (�2.9.2) for class variables, may be used to initialize the class variables of the class (�2.17.4).And in �2.17.4 (http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#19075) it says
Initialization of a class consists of executing its static initializers (�2.11) and the initializers for static fields (�2.9.2) declared in the class. Initialization of an interface consists of executing the initializers for fields declared in the interface (�2.13.3.1).
Before a class or interface is initialized, its direct superclass must be initialized, but interfaces implemented by the class need not be initialized. Similarly, the superinterfaces of an interface need not be initialized before the interface is initialized.
A class or interface type T will be initialized immediately before one of the following occurs:
* T is a class and an instance of T is created.
* T is a class and a static method of T is invoked.
* A nonconstant static field of T is used or assigned. A constant field is one that is (explicitly or implicitly) both final and static, and that is initialized with the value of a compile-time >constant expression. A reference to such a field must be resolved at compile time to a copy of the compile-time constant value, so uses of such a field never cause initialization.
Invocation of certain methods in library classes (�3.12) also causes class or interface initialization. See the Java 2 platform's class library specifications (for example, class Class and package java.lang.reflect) for details.So if you don't want to create and instance or add a method then you can only use (read) or assign a nonconstant static field (the field initialized by the static block should be fine).
The library functions above are not required to initialize the class, so that won't be much help.
Similar Messages
-
Can we add member directly in to dataforms with out editing dataform layout
Hi All,
i have a query regarding dataform can we add member in to dataform with out editing dataform layout .
Member is already in dimension hirerachy . but in my scenario user want to add member directly to dataform with out editing its layout
is it possible ? if its possible how please let know how it is possible.
Thanks in advance please help me out
Regards,
SMYou can add row/column layout you can select: Allow users to dynamically add rows.
It will "Enable users who have write access to the data form to dynamically change and refresh the data form’s definition by adding rows. Selected members that they can access display on the data form. You cannot simultaneously select Allow Users to Dynamically Add Rows and Suppress Missing Data. "
Enabling Users to Add Rows:
http://download.oracle.com/docs/cd/E12825_01/epm.111/hp_admin/ch06s03s15.html
Cheers..!!!
PS: I can see that you have asked 8 questions are all of them are unresolved, its a good practice to mark the answers as correct or helpful, if you think they helped you and close the thread once your got your answers.
Here are few Ex:
hyperion planning
hyperion planning workforce &capex
Edited by: RahulS on Aug 17, 2011 6:09 PM -
How to know the size of the string with out using the length() method
i want to find the lenght of the
String s="Sudha";
with out using the lenght() method.Not true (I mean the part about "The only String
call"). But if it had been true, I might haveagreed
with this:
Assuming one uses the 'exception' approach thenwhat
method other than charAt() is needed?I probably misunderstood your post, I thought you
meant that the only alternative to length() would be
charAt() and catching the exception.There are many ways and if the teacher had said find 5 ways of finding the length of a String then I would have fealt happier because it would have meant the student would have to read and study the whole of the String API.
I like
int length = (s+"sabre").lastIndexOf("sabre"); -
Data filtering in XML report with out changing the underlying query
Hi, This is Nagesh and from Verizon.
I'm testing Query based XML report in Peoplesoft 9.1 app with tools version 8.5.
I'm trying to filter the data on XML Report template with out changing the underlying PS query. I mean filter the data on the report to only specific accounts though the underlying PS query query return transactions booked to all Accounts for a given Legal Entity. Is it possible. any advise or idea is highly appreciated.
Thanks
AgesIf the value is not of importance how come it became obligatory in your program?
Any how you can do one thing...Put some value in your obligatory field, put a debugger point where you are interested in and use the pencil tool to change the value of the field while debugging.
Regards,
Philip. -
i cant remember my password to logon to my mac, how can i change it with out needing the old one?
http://support.apple.com/kb/HT1274
-
Can you use one PC for 2 different Ipods, with out erasing the others music from Itunes?
Can you use one PC for different Ipod touch's , with out erasing the other persons Itunes music?
Yes. See:
How to use multiple iPods, iPads, or iPhones with one computer -
Delivery deleted with out reversing the GR in Inter company PO
Hi Ever one
Can any body suggest the below issue.
By mistake user has deleted Out bound delivery with out reversing the GR in Inter company PO
At the other end receiving site has sold the goods where I am unable to do reverse the GR bez stock is not available, even If create the delivery once again I need to do GR other wish It will be In transit.
kindly help me out
Regards
sudhaHi Kishor
yes, first Goods receipt has to be reverse, but user did mistake
After PO creation, delivery and PGI in VL02N, and Invoice in VF01 finally GR in MB0A with ref to delivery
in reverse also first GR need to be reverse in MBST and Invoice and delivery in VL09.
but by mistake delivery has bee reversed in VL09 with out reversing GR where as it is allowing to do so( this delivery had not been Invoiced )
Awaiting for your reply
Thanks & Regards
sudha -
Why does after i i have unzipped and edited the classes...
Why after i have unzipped and edited the classes in the jar file and zipped them together again, it gives me the message "CAN NOT FIND MAIN CLASS"?
This is after i have edited any class in the .jar zip.I did not edit the Manifest text file,can someone who has experienced this problem show me how to overcome it.
Thank you.
Edited by: Blade_runner on Aug 6, 2008 3:04 PMI hope you realize you're in the wrong forum.
This is not a forum for Java issues experienced when doing some programming on a desktop computer.
This is a forum for questions and issues about the graphical environment named Sun Java Desktop System (JDS) which runs on Solaris and Linux ...
http://en.wikipedia.org/wiki/Java_Desktop_System
Instead, you might consider:
http://forums.sun.com/index.jspa?tab=java -
Can I add my digital copy movie to my iTunes with out using the disk, my gateway laptop/netbook does not have a disk drive I have the unused code and everything, I just can't stuck the movie into the computer itself and my desktop computer has no internet on it. Is there a way to add my movie to my iPod touch 2nd generation tuning 4.2.1
Hiya!
It depends on what kind of digital copy you have. This article goes ino details regarding the two types, and depending on the type you have, you may or may not need the DVD to redeem the code.
Transferring video from DVDs with iTunes digital content
http://support.apple.com/kb/HT1539
I hope this helps! Best wishes and good luck! -
How do i get through find my i phone with out knowing the past apple id or password?
how do i get through find my i phone with out knowing the past apple id or password?
If the iPhone has Activation Lock - that is, it's asking for the previous owner's Apple ID and password to activate the device - then you will need that information, or you'll need to get the previous owner to remove the device from his/her iCloud account:
http://support.apple.com/kb/PH2702
If you can't reach the previous owner or he/she is unwilling to cooperate, then the device is unusable by you. If you recently purchased the iPhone, return it for a refund if you can.
Regards. -
HT1212 im trying to reset my ipod with out deleting the songs
i want to reset my ipod and it is disabled with out deleting thee songs on there
You can't. If you could then the Disabled would be a poor security feature
Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
iOS: Wrong passcode results in red disabled screen
If recovery mode does not work try DFU mode.
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
For how to restore:
iTunes: Restoring iOS software
To restore from backup see:
iOS: How to back up
If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
You can redownload most iTunes purchases by:
Downloading past purchases from the App Store, iBookstore, and iTunes Store -
How to skip a selection screen mandatory field in debugging mode with out changing the code?
Hi Team,
In my report there is two fields on selection screen, one is obligatory field , but i just want to execute the report(for testing per pus) with out entering the data for the mandatory field with out changing the code. could u let me know which event and how to debug the report. or else in debugging mode how can i change that field as non mandatory field.
Regards,
Venkat.If the value is not of importance how come it became obligatory in your program?
Any how you can do one thing...Put some value in your obligatory field, put a debugger point where you are interested in and use the pencil tool to change the value of the field while debugging.
Regards,
Philip. -
Spooling the output of a Query with out displaying the rows
Hello All,
Is it possible to spool the output of
a query/dbms_output.put_line with out displaying
the Query output on the console.
In my case,list of rows in the output is huge, I want
to eliminate displaying the output of query
so that spooling will complete faster.
Thanks in advance.
-SriniYou can do:
SET TERMOUT OFFIn your script before doing the spool command.
You will have to write your query as a .SQL script and run it from SQL*Plus in order for it to work the way you expect.
sqlplus -s username/password @query_script.SQL -
How to display the alv report blocks wise with out using the blocked alv
Hi
How to display the alv report with out using the blocked alv function module.
Thanks
Chinnusee this Standard Program
RPR_ABAP_SOURCE_SCAN -
Can we do a interface With out assigning the TS and BS to the SWC
Hi,
With out assigning the Technical system and Business system to the particular software component.. can we do the Scenario..
my Scenario is the File to RFC... for this... the Receiver system ( SAP- R/3 ) is need to maintain entry in SLD.. or with out that also can we do the scenario..
Because with out maintaining an entry in the SLD.. under a new software component i have created a scenario... it is working fine.. then why we need to assign the Technical system and Business system to all the SWC 's...
Please clear my doubt
Thanks
JainHey Raj
Even help.sap says we need to use Business system for RFC
For Sender RFC
The communication channel in which the RFC adapter is defined must be defined for a service of type Business System in the area Service Without Party. In the PCK, you must create an empty party record.
For Receiver RFC
The communication channel in which the RFC adapter is defined must be defined for a service of type Business System in the area Service Without Party. In the PCK you must create an empty party record.
http://help.sap.com/saphelp_nw04/helpdata/en/67/6d0540ba5ee569e10000000a155106/frameset.htm
You need to mention Gateway Host and gateway service in SM59 for RFC communication,there you need business system.
Thanx
Aamir
Maybe you are looking for
-
How to configure multiple cisco 3750x switches
Hi All, we recently bought 25 x 3750-48PS switches and need to roll them out with similar IOS and configuration. I normally get a console to the switch from my laptop and do one by one. is there a better way or software which can speed up the process
-
JSSE Client and server communication problem .err:untrusted server cert
Hai all, I am trying to communicate JSSE client and server. I have created root.cert(CA),root.key,server.cert,server.key , client.cert and client.key. All these certificates are created using openssl. I have placed root.cert in default keystore cacer
-
Hi, Plugin can be loaded from the link below. This is getting installed on the firefox 3 version but each time I install it on Firefox 4 version it shows the compatibilty error. I have disabled the compatibilty check for firefox in default:config set
-
Checking for empty tags using expression builder for XPATH
I am creating several filters in a mediator for several parallel paths. I am trying to route the mediator to the correct DB adapter based on what tags are empty in the incoming XML. The XML has 1 required tag and 3 optional. So for the expression, I
-
How to configure profile manager in Maverics when DNS is externally managed?
Are there any guides to configuring Profile Manager as a MDM? Here is my story. Recently installed Mac mini at a school where the DNS is externally managed by the Education departments IT group. Upgraded to Maverics and installed Server app. Confi