Nicholas Clark wrote: > > class Foo { > ... > std::size_t spare = 0 > std::size_t allocate = 4096 > std::size_t min_readline = 80 > > and have the compiler know that if I specify a member initialiser in my > my constructor, then that should be used, otherwise to default to using > the value I say. (To avoid the inevitable search/replace if I want to > change that value)
That's actually valid Java syntax (modulo a trailing C<;>). The default value can be any expression (as long as it doesn't involve a reference to the object being constructed, IIRC). In fact Java provides a notion of instance initialiser, run before any specific constructor you're invoking, that initialises such fields, and may run other code. The details aren't very clear to me, since I haven't written any Java code since almost two years. I'm sure someone will correct me if I'm wrong /-/.