• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calendar

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some code in which I want to create a current date for today. Then I want to subtract 3 months worth of time. So for the day Feb 11, 2003 I would want the date to be Nov 11, 2002. Here's my first attempt:

I took a quick look at the add method for Calendar and I thought that this would work for me. This code seems to work fine for me, but my compiler flags the second line as accessing a static field in a non static way. I understand WHAT and WHY the compiler is telling me this. However, alternatives are not working for me. How can I do this the correct way? Thanks in advance.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be able to access a class' public static fields through an instance. What compiler are you using? It works with JDK 1.4.2_01 on Windows 2000.
 
Eric Sexton
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IBM WSAD 5.1. It is only a warning, not an error. In fact I can specify that I want those types of warning to be ignored. I guess I wanted validation that what I was doing is acceptable.
[ November 12, 2003: Message edited by: Eric Sexton ]
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It worked for me, too, but this might be better:

This accesses the static "MONTH" variable using the class, rather than an instance. But either way is syntactically correct.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic