protected constructor confusion

Hi All

Please see the following code


new C1(); is an error. But IDEA is not showing any error and there is Green light.

Is this a bug in IDEA? Or Am I missing something?

Thanks
Anki.N

0
Avatar
Permanently deleted user

Forgot to mention --- Build is 944

0
Avatar
Permanently deleted user


Why would this code be invalid? C2 extends C1 and thus has access to all protected members (including constructors).

0
Avatar
Permanently deleted user

Thats why confusing. Compile this class, it gives error.

Is still access modifiers not stabilized in JLS???

0
Avatar
Permanently deleted user

By the way JDK is 1.3.0_03

0

Imagine you have a protected method

in C1.
It's ok to call

from a method in C2. However it's
not allowed to call foo on an another object of class C1:

<-- error

That's why you can call

from within C2's constructor but cannot usr

.

So it's a bug in Idea, please file a tracker item (btw the bug is still there in 977).

0
Avatar
Permanently deleted user

Please submit an SCR.

--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"

"Anki" <no_mail@jetbrains.com> wrote in message
news:3423438.1070577704896.JavaMail.javamailuser@localhost...

Hi All

>

Please see the following code

 package p1;
>
> public class C1 {
>     protected C1() { } //protected constructor
> }
>
> --------------
>
> package p2;
> import p1.*;
>
> public class C2 extends C1 {
>     public static void amethod() {
>         new C1(); // <<<<---------- This is an error
>     }
> }
> ]]>

>

new C1(); is an error. But IDEA is not showing any error and there is

Green light.
>

Is this a bug in IDEA? Or Am I missing something?

>

Thanks
Anki.N



0
Avatar
Permanently deleted user

The protected constructors is not easy.
http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#72728

You can call protected constructors by "new" operators only in case of inner class, as i can understand

Thanks!

0
Avatar
Permanently deleted user

You learn something new every day. Thanks.

--Dave

0
Avatar
Permanently deleted user

I Just submitted

Thanks.

0

请先登录再写评论。