[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Adding common methods for Enum
|
Hi Vinodh,
Unfortunately no, you cannot use AspectJ to inject methods in Enums, as
is explained in AspectJ 5 manual at chapter 7. You can fill a request
for an enhancement, or look if there is already one open and vote for
it, in both cases adding your use case.
Anyway, I'm pretty sure there is already a method called valueOf() that
will convert the textual (String) name of an Enum to its corresponding
constant.
Simone
vinodh subbiah wrote:
>
> Hi All,
> I have few enum defined in my project , but now i want to provide a
> common methods which will return the Enum for the values we pass as
> String.Like you pass the description and the Enum
>
> For this we have a method
> public static ServiceType getEnum(String name){
> ServiceType serviceType = null;
> for (ServiceType tempServiceType : ServiceType.values()) {
> if( tempServiceType.getName().equalsIgnoreCase( name ) ){
> serviceType = tempServiceType;
> break;
> }
> }
> if( serviceType == null ){
> throw new IllegalArgumentException( "Invalid type: "+name );
> }
> return serviceType;
> }
>
> So instead of using this same code all over the Enum defined, can i
> use aspectJ to have this functionality?
> Please help,
> Regards,
> Vinodh
>
> Vinodh Subbiah,
> 580 Laforet Street,Apt 14
> Windsor N9C3G8
> Canada
> Ph 519-971-7847
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
--
Simone Gianni
http://www.simonegianni.it/
CEO Semeru s.r.l.
Apache Committer