Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Cannot access private field/method declared via ITD from target class

Ain't that a gotcha for someone who has used AspectJ for a few years and
thought he knew a little something about it? You never cease to amaze me
with your teachings, thank you so much. :-)

-- 
Alexander Kriegisch
https://scrum-master.de


Andrew Clement:

> From what I recall the visibility is expressed with respect to the
> aspect - so indeed the class can’t see it. I don’t *think* that
> used to work.
> 
> This is from a time I think when we were more purist about aspects -
> and perhaps it is being a bit too strict these days - when what you
> really want to do is add a new private field to a type, you can’t.
> Perhaps there is another visibility to be expressed ‘private to the
> target and the aspect’ (private shared?).
> 
>
>> Alexander Kriegisch:
>> 
>> I might remember wrong, but I think this used to work at some point
>> in the past, or at least it should. But before I file a Bugzilla
>> ticket, I would like to have your opinion, Andy. Declaring something
>> like
>> 
>> private int MyClass.myField = 0;
>> 
>> private int Account.getMyField() {
>>  return myField;
>> }
>> 
>> basically works and the aspect itself can access the field and the
>> method. But the class they are declared on cannot and Ajc says:
>> 
>> [error] The method getMyField() from the type MyClass is not visible
>> 
>> For a full MCVE which you can just copy & paste and for my other
>> findings, please see my answer here:
>> 
>> https://stackoverflow.com/a/61450184/1082681


Back to the top