digitalmars.D - What does 'final' keyword exactly?
- Andrew Fedoniouk (15/15) Jun 05 2005 E.g. here: (std.openrj)
- Jarrett Billingsley (6/19) Jun 05 2005 Makes it so you can't override that function in derived classes.
- Jarrett Billingsley (3/6) Jun 05 2005 Oops, meant C# and Java.
- Andrew Fedoniouk (16/35) Jun 05 2005 Yep. Thanks. That is in Java.
- Andrew Fedoniouk (7/18) Jun 05 2005 Found answer:
- Jarrett Billingsley (3/10) Jun 06 2005 Ooh goody! Which means that it _will_ work like that :)
- Derek Parnell (30/47) Jun 05 2005 My understanding is that you can't derive a new class from this class
- Andrew Fedoniouk (10/31) Jun 05 2005 [snip]
- Derek Parnell (10/43) Jun 05 2005 I don't know Java. I *told* you what is does in D. I wrote a test progra...
- Andrew Fedoniouk (7/47) Jun 05 2005 Derek, no offence was implied from my side.
E.g. here: (std.openrj) class Field { .... final char[] name() { return m_name; } final char[] value() { return m_value; } ... } Andrew.
Jun 05 2005
"Andrew Fedoniouk" <news terrainformatica.com> wrote in message news:d8081t$2bba$1 digitaldaemon.com...class Field { .... final char[] name() { return m_name; } final char[] value() { return m_value; } ... }Makes it so you can't override that function in derived classes. In other languages (I think C++ and Java, though it's called "sealed" in one of them), when applied to a class, it means the class can't be derived from. But that doesn't work in D.
Jun 05 2005
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:d80akp$2cqh$1 digitaldaemon.com...In other languages (I think C++ and Java, though it's called "sealed" in one of them), when applied to a class, it means the class can't be derived from. But that doesn't work in D.
Jun 05 2005
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:d80akp$2cqh$1 digitaldaemon.com..."Andrew Fedoniouk" <news terrainformatica.com> wrote in message news:d8081t$2bba$1 digitaldaemon.com...Yep. Thanks. That is in Java. Next question is what are the desing goals of having two final functions and left 'record' non-final? (std.openrj) class Field { final char[] name() { return m_name; } final char[] value() { return m_value; } Record record() { return m_record; } } For me it seems that Matthew was trying to use final as a const for returning char[]. Andrew.class Field { .... final char[] name() { return m_name; } final char[] value() { return m_value; } ... }Makes it so you can't override that function in derived classes. In other languages (I think C++ and Java, though it's called "sealed" in one of them), when applied to a class, it means the class can't be derived from. But that doesn't work in D.
Jun 05 2005
final [snip]when applied to a class, it means the class can't be derived from. But that doesn't work in D.Found answer: Sat, 23 Aug 2003 10:23:29 -0700 "Walter" <walter xx digitalmars.com> writes: Looks like a compiler bug. "Carlos Santander B." <carlos8294 xx msn.com> wrote in message news:bi65mo$2a9n$1 xx digitaldaemon.com...What's the purpose of 'final' in D? This code compiles just fine: final class A {} class B:A { } void main() { B b=new B(); } ------------------------- Carlos Santanderhttp://www.digitalmars.com/d/archives/16022.html
Jun 05 2005
"Andrew Fedoniouk" <news terrainformatica.com> wrote in message news:d80eg3$2fh0$1 digitaldaemon.com...final [snip]Ooh goody! Which means that it _will_ work like that :)when applied to a class, it means the class can't be derived from. But that doesn't work in D.Found answer: Sat, 23 Aug 2003 10:23:29 -0700 "Walter" <walter xx digitalmars.com> writes: Looks like a compiler bug.
Jun 06 2005
On Sun, 5 Jun 2005 18:14:33 -0700, Andrew Fedoniouk wrote:E.g. here: (std.openrj) class Field { .... final char[] name() { return m_name; } final char[] value() { return m_value; } ... } Andrew.My understanding is that you can't derive a new class from this class *and* override any of the 'final' members. That is, you can't do this sort of thing ... class Field { char[] m_name; char[] m_value; final char[] name() { return m_name; } final char[] value() { return m_value; } } class SField : Field { char[] mx_name; char[] mx_value; char[] name() // Fails. { return mx_name; } } -- Derek Melbourne, Australia 6/06/2005 12:02:05 PM
Jun 05 2005
"Derek Parnell" <derek psych.ward> wrote in message news:leailo4fvus.m2wubh7asozc.dlg 40tude.net...On Sun, 5 Jun 2005 18:14:33 -0700, Andrew Fedoniouk wrote:[snip] Thanks, Derek, I know what 'final' does in Java. But what it does in D? Asking because 'final' is not defined in documentation. At least I didn't find it. In fact 'final' in Java does many things, I would say too many. http://www.codeguru.com/java/tij/tij0071.shtml Andrew.E.g. here: (std.openrj) class Field { .... final char[] name() { return m_name; } final char[] value() { return m_value; } ... } Andrew.My understanding is that you can't derive a new class from this class *and* override any of the 'final' members. That is, you can't do this sort of thing ...
Jun 05 2005
On Sun, 5 Jun 2005 19:39:40 -0700, Andrew Fedoniouk wrote:"Derek Parnell" <derek psych.ward> wrote in message news:leailo4fvus.m2wubh7asozc.dlg 40tude.net...I don't know Java. I *told* you what is does in D. I wrote a test program and tried it out before replying to your post.On Sun, 5 Jun 2005 18:14:33 -0700, Andrew Fedoniouk wrote:[snip] Thanks, Derek, I know what 'final' does in Java. But what it does in D?E.g. here: (std.openrj) class Field { .... final char[] name() { return m_name; } final char[] value() { return m_value; } ... } Andrew.My understanding is that you can't derive a new class from this class *and* override any of the 'final' members. That is, you can't do this sort of thing ...Asking because 'final' is not defined in documentation. At least I didn't find it.I agree; its meaning is not documented.In fact 'final' in Java does many things, I would say too many.Whatever ... I just looked at what it does in D - to answer your original question with respect to the code sample you gave. -- Derek Melbourne, Australia 6/06/2005 1:21:14 PM
Jun 05 2005
"Derek Parnell" <derek psych.ward> wrote in message news:ozn0oihlm1z6$.mcz62ecxpoz4$.dlg 40tude.net...On Sun, 5 Jun 2005 19:39:40 -0700, Andrew Fedoniouk wrote:Derek, no offence was implied from my side. I simply did not get what 'final' is doing in code fragment I provided from openrj. For me it seems like remnants of previous desicisions/ implementations. That is why I asked. Again no claims of any sort. Andrew."Derek Parnell" <derek psych.ward> wrote in message news:leailo4fvus.m2wubh7asozc.dlg 40tude.net...I don't know Java. I *told* you what is does in D. I wrote a test program and tried it out before replying to your post.On Sun, 5 Jun 2005 18:14:33 -0700, Andrew Fedoniouk wrote:[snip] Thanks, Derek, I know what 'final' does in Java. But what it does in D?E.g. here: (std.openrj) class Field { .... final char[] name() { return m_name; } final char[] value() { return m_value; } ... } Andrew.My understanding is that you can't derive a new class from this class *and* override any of the 'final' members. That is, you can't do this sort of thing ...Asking because 'final' is not defined in documentation. At least I didn't find it.I agree; its meaning is not documented.In fact 'final' in Java does many things, I would say too many.Whatever ... I just looked at what it does in D - to answer your original question with respect to the code sample you gave.
Jun 05 2005