Web Log di Adrian Florea

"You know you've achieved perfection in design, not when you have nothing more to add, but when you have nothing more to take away." Antoine de Saint-Exupery
posts - 440, comments - 2715, trackbacks - 3944

My Links

Archives

Post Categories

Image Galleries

.RO Blogs

.RO People

.RO Sites

Blogs

Furls

Links

vinCitori

The class X already contains a definition for Y

Appena premuto il bottone "Inserici" per il post precedente, scopro un altro quiz (sempre della Session TS-2575 di 2004 JavaOne Conference presentata da Joshua Bloch e Neal Gafter) irriproducibile in C#: "5. Shades of Gray" (per essere precisi, l'autore in realtà è Dominik Gruntz e il quiz appare per la prima volta un anno e mezzo fa su Journal of Object Technology in un articolo interessante, intitolato "C# and Java: The Smart Distinctions").

Si tratta di un'altra "feature" di Java: "Java makes a distinction between the namespace of fields, methods and nested classes within a class, i.e., it is possible to declare a field, a method and a static inner class with the same name.", ovviamente con lo svantaggio che: "As nested classes and fields are accessed with the same scope resolution operator, access may be diffcult if both a field and a nested class are declared with the same name.". Ma, continua Dominik Gruntz, "In C# this problem is also fixed. All declarations in a class fall into the same namespace, thus it is not possible to declare a field and a nested class with the same name. C# also prohibits the declaration of fields and methods with the same name.". Il compilatore C# dà questo errore di compilazione: "The class 'X' already contains a definition for 'Y'"

La parola delle specifiche:

C# Language Specification, 2nd edition Java Language Specification, 2nd edition
17.2
"The name of a constant, field, property, event, or type must differ from the names of all other members declared in the same class."
6.5
"Types, methods, and fields may have the same name."

Print | posted on lunedì 2 agosto 2004 21:01 | Filed Under [ Quiz Sharp Carillon .NET ]

Powered by:
Powered By Subtext Powered By ASP.NET