Annotation
package com.liguoliang.lang; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) /** * http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/RetentionPolicy.html * @author Guoliang * */ public @interface Note { String title() default "Note"; String details(); }
Usage
package com.test.meta; import static org.junit.Assert.*; import org.junit.Test; import com.liguoliang.lang.Note; @Note(details="This test is for Annotation") public class TestMeta { @Test public void test() { Classklass = TestMeta.class; assertTrue(klass.isAnnotationPresent(Note.class)); Note note = klass.getAnnotation(Note.class); System.out.println("Class: " + klass.getCanonicalName() + "Note: " + note.title() + ": " + note.details()); } }
Output:
Class: com.test.meta.TestMetaNote: Note: This test is for Annotation
* PECS stands for producer-extends, consumer-super
* Do not use wildcard types as return
types. Rather than providing additional flexibility for your users, it would force them to use wildcard types in client code.
.
@Test /** * PECS stands for producer-extends, consumer-super. */ public void testAccountListUtils() { ListcorporationAccounts = new ArrayList (); corporationAccounts.add(new CorporationAccount(1, "Google")); corporationAccounts.add(new CorporationAccount(2, "Yahoo")); List allAccounts = new ArrayList<>(); AccountListUtils. mergeUserList(corporationAccounts, allAccounts); assertEquals(corporationAccounts.size(), allAccounts.size()); }
package com.liguoliang.lang.collection; import java.util.List; import com.jpm.model.IAccount; public class AccountListUtils < T extends IAccount >{ public staticvoid mergeUserList(List tobeMerged, List allAccounts) { allAccounts.addAll(tobeMerged); } }
@Test public void wildCard() { ListcorporationAccounts = new ArrayList<>(); corporationAccounts.add(new CorporationAccount(1, "GE")); corporationAccounts.add(new CorporationAccount(2, "IBM")); IAccount account = getUserById(corporationAccounts, 2); System.out.println(account.getAccountName()); } /** * List and List are treated as two different types. * If we use List as the parameter type, and call the method by getUserId(List , * will got this compile Error: * The method getUserById_iAccount(List , int) in the type LearnGeneric * is not applicable for the arguments (List , int); * @param accountList * @param id * @return */ public IAccount getUserById(List< ? extends IAccount> accountList, int id) { for (IAccount iAccount : accountList) { if(iAccount.getAccountId().equals(id)) { return iAccount; } } return null; } /** * Note: getUserById(List and getaUserById(List ) are not reloading methods: * Erasure of method getUserById(List , int) is the same as another method in type LearnGeneric * @param accountList * @param id * @return */ public IAccount getUserById_withoutWildCard(List accountList, int id) { for (IAccount iAccount : accountList) { if(iAccount.getAccountId().equals(id)) { return iAccount; } } return null; }
ArrayList in JDK is the best example. however, this one is created by myself:
Requirement:
As a (junior) Excel user, I want to compare two columns and change the background colour for the cells which is not consistent.
Steps:
1. Create New Rule:
you may select the B2, and click Conditional Formatting > New Rule:
Configure the formula and the format.
2. Apply the the rule:
You may right click the ‘+’and then drug, select the ‘Fill formatting Only’ when drop.
Or you can use Conditional Formatting > Manage Rules:
to change the “Applies to…” and then “Apply”
Sybase doesn’t have this feature, however we can use lift/right join + union to get it:
SELECT * FROM A LEFT OUTER JOIN B ON…
UNION
SELECT * FROM A RIGHT OUTER JOIN B ON…
UNIN will remove the duplicated records.
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.