Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

about AspectJ

Thread view: 
applex - 23 Apr 2006 16:09 GMT
I created two files:
PreConditionExample.java
public class PreConditionExample {
    public double sqrt(double p) {
        return Math.sqrt(p);
    }

    public static void main(String[] args) {
        PreConditionExample t = new PreConditionExample();
        System.out.println("sqrt -4 : "+t.sqrt(-4));
        System.out.println("sqrt 9 : "+t.sqrt(9));
    }
}

PreconditionAspect.aj
public aspect PreconditionAspect
{
    pointcut sqrtPc(double param) : call ( * Math.sqrt(double)) &&
args(param) ;

    before(double param ) : sqrtPc(param)
    {

        if (param < 0)
        {
            System.out.println("illegal parameter");
            //throw new RuntimeException();
        }
    }

}

but it doesn't work in this way. "illegal parameter " was not printed.
but I put them in the same file, it works.
Why?
help/
Mark Thomas - 23 Apr 2006 17:40 GMT
> I created two files:
> PreConditionExample.java
[quoted text clipped - 32 lines]
> Why?
> help/

There's nothing wrong with the code.  When I run it, I get:

illegal parameter
sqrt -4 : NaN
sqrt 9 : 3.0

as expected.  How are you compiling them?

Mark


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.