473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

enumeration

Hi,

Java doe not have the data type enum. I am starting to learn it in Java and
find it confusing.

1) Whats the point in having enum? Java does have it, so probably there is a
way around it.
2) Can someone show a SIMPLE code of how enum works?
WD

Jul 19 '05 #1
4 5252
"Web Developer" <no****@hotmail.com> wrote...
Java doe not have the data type enum. I am starting to learn it in Java and find it confusing.
Find what confusing? Java? No doubt.
1) Whats the point in having enum? Java does have it, so probably there is a way around it.
Enums are "named constants". Each enum is its own type. Using enums
promotes strong typing (no, I don't mean hitting keys with your fingers).
2) Can someone show a SIMPLE code of how enum works?


#include <iostream>

enum Protocol { FTP = 21, HTTP = 80, HTTPS = 143 };

void foo(int)
{
std::cout << "foo(int) called\n";
}

void foo(Protocol)
{
std::cout << "foo(Protocol) called\n";
}

int main()
{
foo(42);
foo(HTTPS); // _not_ the same as foo(143)
}

Victor
Jul 19 '05 #2

Web Developer wrote:

Hi,

Java doe not have the data type enum. I am starting to learn it in Java and
find it confusing.

1) Whats the point in having enum? Java does have it, so probably there is a
way around it.
No.
2) Can someone show a SIMPLE code of how enum works?


Yes.

#include <iostream>

enum vote { no, yes };

std::ostream& operator <<(std::ostream& os, vote v) {
return os << (!v ? "no" : "yes");
}

vote operator or(vote lhs, vote rhs) {
return vote(lhs | rhs);
}

int main() {
std::cout << (yes or no) << std::endl;
}

Well, try also this:

#include <cstdio>
#include <climits>
//#include <iostream>

int main() {
enum { iMIN = LONG_MIN, uMAX = ULONG_MAX } ld = iMIN, lu = uMAX;
printf("%ld ** %lu\n", LONG_MIN, ULONG_MAX);
printf("%ld ** %lu\n", static_cast<signed long>(ld),
static_cast<unsigned long>(lu));
// std::cout << ld << " ** " << lu << std::endl;
}

regards,
alexander.
Jul 19 '05 #3
Web Developer wrote:
Hi,

Java doe not have the data type enum. I am starting to learn it in Java and
find it confusing.
Well, this is a C++ 'group, not a Java 'group.
1) Whats the point in having enum? Java does have it, so probably there is a
way around it.
But you just said "Java doe not have" it.
2) Can someone show a SIMPLE code of how enum works?


If there's any C++ question buried in this, please clarify what you're
asking for. Otherwise, try asking in comp.lang.java.help.

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit.

Jul 19 '05 #4
Dear mate,

There's a little survey about the general uses of 'enum's started by
me in comp.lang.c++ under the title "C++ programmers! How do you use
your 'enum's ?", and in comp.lang.c under the title "C programmers!
How do you use your 'enum's ?".
You may find these two threads useful.

Regards,
//rk
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
8
by: aevans1108 | last post by:
Greetings I can't seem to inherit enumerated values from a globally defined type in my XML schema. XmlSchema.Compile() doesn't like it. Here's the schema. <?xml version="1.0"...
2
by: Mark | last post by:
Assume you have an enumeration like PhoneType { Home, Business, Cell }. This enumeration corresponds with a lookup/dictionary table in your database like: phone_cd | phone_descr 1 ...
4
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
1
by: Stefano G. | last post by:
I have a WSDL containing this enumeration type <xsd:simpleType name="item_type_enum"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="VCD"/> <xsd:enumeration value="SVCD"/>...
27
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to...
3
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
0
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
3
by: eXt | last post by:
For a realtime-application (half an application at least, kind of a framework) I am working with I need a event managing system and naturally it must be fast. I have defined a set of available...
3
by: muler | last post by:
hi all, After reading this excerpt from "The C# Programming Language", (By Anders) I tried to check it out. Unfortunately, I'm getting compile errors. Can anyone illustrate this with an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.