Friday, November 29, 2013

Using the same identifier for a Type and a Class: What is the semantic effect of that syntax?


[Moi:] "Notice how the identifier Customer is used with 2 different purposes. IIRC, neither C++ nor Java allows such confusing usage."


[Mike:] I don't know about Java but C++ certainly allow something like that:



class foo {
};

class bar {
foo foo;
};

I was right, but only about Java. In another forum somebody wrote the following:


"This has nothing unusual in C#.


"In Java you would write:




Customer getCustomer()
void setCustomer(Customer customer)



"C# provides a convienient way to declare both getX() and setX() in one single member, usually called X.


No comments:

Post a Comment