Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Enumeration reference

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

If enumerations can be declared outside of a class, then what class do they belong to? To elaborate, i have source file test1.java which has the class test1 and outside of the class i have an enumeration declaration. To refer to this enumeration from another class i am having to do a reference like this test1.Enum e = test.Enum.Val1. Should the declaration be tied to the class even if it is outside the class. Is it tied to the source file name? I guess i am spiralling.

appreciate all the help
venu
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi venu,


If enumerations can be declared outside of a class, then what class do they belong to?


It doesn't belong to a class. But it is a class on its own. Actually there is no difference in declaring an enum or a class within a file.

Given:

then the compiler generates the class files A.class, B.class, C.class.

In order to understand enums well, it is helpfull to use a decompiler. Then you could see something like

This also explains, for example, why an enum can't extend a given class (because it already extends class Enum), but can implement any number of interfaces.

Ralph
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ralph Jaus:
to use a decompiler



How to use a decompiler?
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use "Jad", for example, it's freeware. After installation you double click the class file and it recovers the programm from the bytecode. That's helpfull with constructions like enums or generics, because you can see the code that was added/generated by the compiler.

You can also use the decompiler included in the jse. It's invoked by the command "javap". In the code sample above "javap A" delivers some information. But Jad is much better because it shows Java code.
 
Bhushan Chhajed
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ralph Jaus:
You can use "Jad", for example, it's freeware.



Thanks Ralph, but I was unable to find any specific software.
Can you please guide and give me some exact link of the latest free download.

Thanks.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I was unable to find any specific software.
Can you please guide and give me some exact link of the latest free download.


Google for "jad decompiler".
 
venu surampudi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ralph, i think the whole decompile to understand what is compiled is a very good idea.
 
reply
    Bookmark Topic Watch Topic
  • New Topic