Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with static method issue

 
Mike Kremer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Mike Kremer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic