• 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

abstract method TimeZone.getRawOffset

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
looks getRawOffset() of TimeZone is abstract method. I thought it must be extended by subclass to implement the abstract method to use the function getRawOffset.

getRawOffset
public abstract int getRawOffset()

but it can be done TimeZone.getDefault().getRawOffset() directly.

System.out.println(" Tiemzoen Rawoffset is " + TimeZone.getDefault().getRawOffset() + ".\n");

What is wrong with my thinking?

Thanks,
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to look at a concrete subclass of TimeZone like SimpleTimeZone.
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, SimpleTimeZone is concrete class. but TimeZone getDefault() returns the instance of timezone, not SimpleTimeZone.

As the code works fine, I know somthing wrong about my thinking, and hope to make it clear.
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if this will give you what you are looking for but you can try to retrieve the offset for your TimeZone with the Calendar.ZONE_OFFSET field number. Create a Calendar instance and then try retrieving the ZONE_OFFSET using that field number.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Jiang:
Yes, SimpleTimeZone is concrete class. but TimeZone getDefault() returns the instance of timezone, not SimpleTimeZone.

As the code works fine, I know somthing wrong about my thinking, and hope to make it clear.


You can indeed not instantiate an abstract class or an interface. But you can have a variable of which the type is an abstract class or interface and have it refer to an instance of a conrete class that extends the abstract class or implements the interface, and then you can call any method in the abstract class or interface. For example:

In fact, coding to the interface and not to a specific implementation, like the example above shows, is good practice.

TimeZone.getDefault() indeed returns a TimeZone and not a SimpleTimeZone. That's good - your program doesn't need to know what concrete implementation of TimeZone is provided. If you try this, you'll see that it returns a sun.util.calendar.ZoneInfo (at least, in Java 6.0 - in other versions is might return something else):

Ofcourse, sun.util.calendar.ZoneInfo is a concrete subclass of java.util.TimeZone.
[ November 22, 2006: Message edited by: Jesper Young ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic