Forums Register Login

Help with static method issue

+Pie Number of slices to send: Send
Hi,

I am seeing something strange and I don't see how or why it could happen. If someone can help 'enlighten' me, it would be very appreciated.

I have an abstract class, Product, that contains a static public void method, createPrototypes(). I am calling Product.createPrototypes() during my application bootup but the code in the method is not reached or processed. The application just hangs up when ran without any errors. Do to this app being ran on an old device I am using jdk1.1.8.

***
Scenario 1: If I run the code below, I get the console output:
>Before method call.

I do not get any errors or any other output to the console; the app just hangs up there.
***
Scenario 2: If I run the code and uncomment the section that I have commented below, it runs fine.....why???
>Before method call.
>In Product.createPrototypes()
>After method call.
***


Thanks in advance!
+Pie Number of slices to send: Send
Welcome to JavaRanch
+Pie Number of slices to send: Send
I copied and pasted your code without any changes and got this output

[Campbell@localhost java]$ java DeviceSession
Before method call.
In Product.createPrototypes()
After method call.

I can't find anything wrong with it, apart from trying to call a non-static method from main().
+Pie Number of slices to send: Send
Did you compile and run the code with jdk 1.1.8? I get the correct results when compiling and running with jdk 1.3.1 but I have to use 1.1.8 because that is the jre that is on the device that I'm programming on.

If you did use jkd 1.18, are there compiler settings or something that can cause static methods to not be loaded or linked until an instance of the class that contains the method is created. That is what seems to be happening to me. The static method is not 'present' during runtime until an instance of the class is created.
Straws are for suckers. Now suck on this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1152 times.
Similar Threads
static and abstract methods
Dan's Thread question...
Why a non-abstract Parent Class can be extended by an abstract Child Class ?
invocation of finalize() method
Abstract Classes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:44:33.