Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javaʹÓÃͨÅä·û¼ò»¯·ºÐÍʹÓÃ

ÔÚʹÓà Java™ ÓïÑԵķºÐÍʱ£¬Í¨Åä·û·Ç³£ÁîÈËÀ§»ó£¬²¢ÇÒ×î³£¼ûµÄÒ»¸ö´íÎó¾ÍÊÇÔÚʹÓÃÓнçͨÅä·ûµÄÁ½ÖÖÐÎʽµÄÆäÖÐÖ®Ò»£¨“? super T” ºÍ “? extends T”£©Ê±³öÏÖ´íÎó¡£Äú³ö´íÁËÂ𣿱ð¾ÚÉ¥£¬¼´Ê¹ÊÇר¼ÒÒ²»á·¸ÕâÖÖ´íÎ󣬱¾Ô Brian Goetz ½«Õ¹Ê¾ÈçºÎ±ÜÃâÕâ¸ö´íÎó¡£
ÔÚ Java ÓïÑÔÖУ¬Êý×éÊÇЭ±äµÄ£¨ÒòΪһ¸ö Integer ͬʱҲÊÇÒ»¸ö Number£¬Ò»¸ö Integer Êý×éͬʱҲÊÇÒ»¸ö Number Êý×飩£¬µ«ÊÇ·ºÐͲ»ÊÇÕâÑùµÄ£¨List<Integer> ²¢²»µÈÓÚ List<Number>£©¡£ÈËÃÇ»áÕùÂÛÄÄЩѡÔñÊÇ “ÕýÈ·µÄ”£¬ÄÄЩѡÔñÊÇ “´íÎóµÄ” — µ±È»£¬Ã¿ÖÖÑ¡Ôñ¶¼¸÷ÓÐÓÅȱµã — µ«ÓÐÒ»µãºÁÎÞÒÉÎÊ£¬´æÔÚÁ½ÖÖʹÓòî±ðºÜСµÄÓïÒå¹¹ÔìÅÉÉúÀàÐ͵ÄÀàËÆ»úÖÆ£¬Õ⽫µ¼Ö´óÁ¿´íÎóºÍÎó½â¡£
ÓнçͨÅä·û£¨Ò»Ð©ÓÐȤµÄ “? extends T” ͨÓÃÀàÐÍ˵Ã÷·û£©ÊÇÓïÑÔÌṩµÄÒ»ÖÖ¹¤¾ß£¬ÓÃÀ´´¦ÀíЭ±äÐÔȱ·¦ — ÓнçͨÅä·ûÔÊÐíÀàÉùÃ÷·½·¨²ÎÊý»ò·µ»ØÖµºÎʱ¾ßÓÐЭ±äÐÔ£¨»òÏà·´£¬ÉùÃ÷·½·¨²ÎÊý»ò·µ»ØÖµºÎʱ¾ßÓÐÄæ±äÐÔ£¨contravariant£©£©¡£ËäÈ»Á˽âºÎʱʹÓÃÓнçͨÅä·ûÊÇ·ºÐͽÏΪ¸´Ôӵķ½Ã棬µ«ÊÇ£¬Ê¹ÓÃÓнçͨÅä·ûµÄѹÁ¦Í¨³£¶¼ÂäÔÚ¿â×÷ÕßµÄÉíÉÏ£¬¶ø·Ç¿âÓû§¡£×î³£¼ûµÄÓнçͨÅä·û´íÎó¾ÍÊÇÍü¼ÇʹÓÃËüÃÇ£¬Õâ¾ÍÏÞÖÆÁËÀàµÄʹÓ㬻òÊÇÇ¿ÖÆÓû§²»µÃ²»ÖØÓÃÏÖÓеÄÀà¡£
ÓнçͨÅä·ûµÄ×÷ÓÃ
ÈÃÎÒÃÇ´ÓÒ»¸ö¼òµ¥µÄ·ºÐÍÀ࿪ʼ£¨Ò»¸ö³ÆΪ Box µÄÖµÈÝÆ÷£©£¬Ëü³ÖÓÐÒ»¸ö¾ßÓÐÒÑÖªÀàÐ͵ÄÖµ£º
public interface Box<T> {
public T get();
public void put(T element);
}
ÓÉÓÚ·ºÐͲ»¾ß±¸Ð­±äÐÔ£¬Box<Integer> ²¢²»µÈͬÓÚ Box<Number>£¬¾¡¹Ü Integer ÊôÓÚ Number¡£µ«ÊǶÔÓÚ Box ÕâÑùµÄ¼òµ¥·ºÐÍÀàÀ´Ëµ£¬Õâ²»³ÉÎÊÌ⣬²¢ÇÒ³£³£±»ºöÂÔ£¬ÒòΪ Box<T> µÄ½Ó¿ÚÍêÈ«Ö¸¶¨Îª T ÀàÐ͵ıäÁ¿ — ¶ø²»ÊÇͨ¹ý T ·ºÐÍ»¯µÄÀàÐÍ¡£Ö±½Ó´¦ÀíÀàÐͱäÁ¿ÔÊÐíʵÏÖ¶à̬ÐÔ¡£Çåµ¥ 1 չʾÁËÕâÖÖ¶à̬ÐÔµÄÁ½¸öʾÀý£º»ñÈ¡ Box<Integer> µÄÄÚÈÝ£¬²¢½«Ëü×÷Ϊһ¸ö Number£¬È»ºó½«Ò»¸ö Integer ·ÅÈë Box<Number> ÖУº
Çåµ¥ 1. ͨ¹ý·ºÐÍÀàÀûÓùÌÓеĶà̬ÐÔ

Box<Integer> iBox = new BoxImpl<Integer>(3);
Number num = iBox.get();
Box<Number> nBox = new BoxImpl<Number>(3.2);
Integer i = 3;
nBox.put(i);
ͨ¹ýʹÓüòµ¥µÄ Box À࣬ʹÎÒÃÇÈ·ÐÅ¿ÉÒÔûÓÐЭ±äÐÔ£¬ÒòΪÔÚÐèҪʵÏÖ¶à̬


Ïà¹ØÎĵµ£º

Ò»¸öJavaµÄ×Ö·û´®³£ÓÃÀà

package com.tienway.util;
import java.util.ArrayList;
public class StringUtil
{

public static String ContextType1ToType2(String Type1Context)
{
if (Type1Context== null || Type1Context.length() == 0)
{
return "";
}
char[] c = Type1Con ......

JAVAÀà×°ÔØÆ÷classloaderºÍÃüÃû¿Õ¼änamespace

JAVAÀà×°ÔØÆ÷classloaderºÍÃüÃû¿Õ¼änamespace
  JAVAÐéÄâ»úͨ¹ý×°ÔØ¡¢Á¬½ÓºÍ³õʼ»¯Ò»¸öJAVAÀàÐÍ£¬Ê¹¸ÃÀàÐÍ¿ÉÒÔ±»ÕýÔÚÔËÐеÄJAVA³ÌÐòËùʹÓá£ÆäÖУ¬×°ÔؾÍÊǰѶþ½øÖÆÐÎʽµÄJAVAÀàÐͶÁÈëJAVAÐéÄâ»úÖС£Á¬½Ó¾ÍÊÇ°ÑÕâÖÖÒѾ­¶ÁÈëÐéÄâ»úµÄ¶þ½øÖÆÐÎʽµÄÀàÐÍÊý¾ÝºÏ²¢µ½ÐéÄâ»úµÄÔËÐÐʱ״̬ÖÐÈ¥¡£Á¬½Ó½×¶Î·ÖΪÈý¸ö²½Ö裭ÑéÖ¤¡¢× ......

Java¾²Ì¬´úÂë¼ì²é¹¤¾ß±Ê¼Ç

code review ¹¤¾ßÁбí
1.´úÂë¸ñʽ¼ì²écheckstyle;
2.ÐÔÄÜ°²È«×î¼Ñʵ¼ù¼ì²éRAD Software AnalyzerºÍFindBug;
3.ÒÀÀµ¼ì²éJDepend;
4.Öظ´ÐÔ¼ì²éeclipse PMD²å¼þ;
5.¸´ÔӶȼì²éeclipse Metrics²å¼þ;
6.Э×÷¹¤¾ßJupiter
 
Jupiter
1.Unset±íʾûÓÐÑ¡Ôñ£¬¶ø²»ÊÇÒ»¸ö¾ßÌåÀàÐÍ
2.Èý¸ö½×¶ÎÓÐĬÈϵÄFilterÌõ¼þ£ ......

JAVA ¶ÔÏóºÍÀà

String s = new Date().toString();¿ÉÒÔÖ±½Ó´´½¨ÍêжÔÏóºó¾ÍÁ¢¼´ÓÃÆäµÄ·½·¨¡£
Ò»¸ö¶ÔÏó±äÁ¿²¢Ã»ÓÐʵ¼Ê°üº¬Ò»¸ö¶ÔÏ󣬶øÊǽö½öÒýÓÃÒ»¸ö¶ÔÏó¡£
GregorianCalendarÀà
javaÉè¼ÆÕß¾ö¶¨°Ñ±£´æʱ¼äÓë¸øʱ¼äµãÃüÃû·Ö¿ªÀ´£¬ÕâÑù¾ÍÓÐÁ½¸öÀà,dateºÍGregorianCalendar.Ò»¸öÓÃÀ´±íʾʱ¼äµã£¬Ò»¸öÓÃÀ´±íʾ´ó¼ÒÊìϤµÄÈÕÀú±íʾ·¨¡£ÊÂ浃 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ