"Crouchez" <blah@bllllllahblllbllahblahblahhh.com> wrote in message
news:O6NCi.120110$p7.76442@fe2.news.blueyonder.co.uk...
> On Sep 1, 10:07 pm, "Crouchez" <b...@bllllllahblllbllahblahblahhh.com>
> wrote:
>
>> I can't the interface's method is protected.
>
> Why/How is the interface's method protected?
>
> AFAIK, you cannot even compile an interface with a protected method.
> You can have default (none), public or abstract modifiers only.
>
> -cheers,
> Manish
>
> Sorry it's an abstract class not an interface
theClass.newInstance---
"Creates a new instance of the class represented by this Class object. The
class is instantiated as if by a new expression with an empty argument list.
The class is initialized if it has not already been initialized."
Class theClass = Class.forName("classy");
MyClass obj = (MyClass)theClass.newInstance(); //not like a new MyClass() ?
obj.doSomething(); //protected doSomething can't be accessed ?
Won't compile because doSomething is protected?
Crouchez - 03 Sep 2007 06:53 GMT
>> On Sep 1, 10:07 pm, "Crouchez" <b...@bllllllahblllbllahblahblahhh.com>
>> wrote:
[quoted text clipped - 23 lines]
>
> Won't compile because doSomething is protected?
btw, classy.class extends MyClass which has a protected method doSomething()
Lew - 03 Sep 2007 08:07 GMT
>>> On Sep 1, 10:07 pm, "Crouchez" <b...@bllllllahblllbllahblahblahhh.com>
>>> wrote:
[quoted text clipped - 25 lines]
>
> btw, classy.class extends MyClass which has a protected method doSomething()
Class names should begin with an upper-case letter, thus, "Classy".
You should read up on access. The "protected" modifier means that the method
can only be invoked:
- within the defining class itself,
- from a class in the same package,
or
- from a class that inherits from the defining class.
Clearly your invoking class is none of the above with respect to MyClass,
therefore it does not have access to the protected methods of MyClass.
Since you do not show the definition of the invoking class it's hard to advise
how to fix that.

Signature
Lew
Crouchez - 03 Sep 2007 07:08 GMT
>> On Sep 1, 10:07 pm, "Crouchez" <b...@bllllllahblllbllahblahblahhh.com>
>> wrote:
[quoted text clipped - 23 lines]
>
> Won't compile because doSomething is protected?
Roedy, Reflection does actually work - but you mention it's slow - why slow?
Roedy Green - 03 Sep 2007 07:29 GMT
On Mon, 03 Sep 2007 06:08:30 GMT, "Crouchez"
<blah@bllllllahblllbllahblahblahhh.com> wrote, quoted or indirectly
quoted someone who said :
>Roedy, Reflection does actually work - but you mention it's slow - why slow?
It works, but it is very clumsy compared with direct calls or using
Class.forName with Interfaces.
Just follow the source code for what happens to do a Method.invoke.
There is on heck of a lot of dicking around before it actually does
the call.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com