I\'m trying to shift from C++ to Java.
What I wonder is, in C++, after a class definition, a semicolon (;
) is required, but in Java it isn\'t.
T
I'm not familiar with Java, but the reason why there's an extra semicolon needed is because you can define an anonymous class, inside functions. For instance:
void routine(const int x, const int y)
{
class { public: int x; int y; } my_instance;
my_instance.x = x;
my_instance.y = y;
// ... etc
}
You'll usually see this more with structs than with classes, to capture some important variables of a big class.
void f(const BigClass& big_class)
{
struct { std::string str; int i; } props;
props.str = big_class.GetFilename();
props.i = big_class.GetID();
// etc...
}