Java Annotations

前端 未结 8 807
天命终不由人
天命终不由人 2020-12-02 05:32

What is the purpose of annotations in Java? I have this fuzzy idea of them as somewhere in between a comment and actual code. Do they affect the program at run time?

8条回答
  •  有刺的猬
    2020-12-02 05:53

    Annotations when it comes to EJB is known as choosing Implicit middle-ware approach over an explicit middle-ware approach , when you use annotation you're customizing what you exactly need from the API for example you need to call transaction method for a bank transfer : without using annotation : the code will be

    transfer(Account account1, Account account2, long amount)    
    {
       // 1: Call middleware API to perform a security check
       // 2: Call middleware API to start a transaction
       // 3: Call middleware API to load rows from the database
       // 4: Subtract the balance from one account, add to the other
       // 5: Call middleware API to store rows in the database
       // 6: Call middleware API to end the transaction
    }
    

    while using Annotation your code contains no cumbersome API calls to use the middle- ware services. The code is clean and focused on business logic

    transfer(Account account1, Account account2, long amount) 
    {
       // 1: Subtract the balance from one account, add to the other
    }
    

提交回复
热议问题