June 06, 2005
E.g. here: (std.openrj)

class Field
{
....
    final char[]  name()
    {
        return m_name;
    }
    final char[]  value()
    {
        return m_value;
    }
...
}

Andrew.


June 06, 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.


June 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
June 06, 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.

Oops, meant C# and Java.


June 06, 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:
>
>> 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 ...

[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.




June 06, 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...
>> 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.

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.


June 06, 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 Santander

http://www.digitalmars.com/d/archives/16022.html


June 06, 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...
>> 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 ...
> 
> [snip]
> 
> Thanks, Derek,
> I know what 'final' does in Java. But what it does in D?

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.

> 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
June 06, 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 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:
>>>
>>>> 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 ...
>>
>> [snip]
>>
>> Thanks, Derek,
>> I know what 'final' does in Java. But what it does in D?
>
> 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.
>
>> 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, 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.




June 06, 2005
"Andrew Fedoniouk" <news@terrainformatica.com> wrote in message news:d80eg3$2fh0$1@digitaldaemon.com...
>
> 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.

Ooh goody!  Which means that it _will_ work like that :)


Top | Discussion index | About this forum | D home