ÀûÓÃjavax.tools¶¯Ì¬±àÒëÖ´ÐÐjava´úÂë
²Î¿¼£ºÊ¹Óà javax.tools ´´½¨¶¯Ì¬Ó¦ÓóÌÐò
¡¡¡¡javax.tools °üÊÇÒ»ÖÖÌí¼Óµ½ Java SE 6 µÄ±ê×¼ API£¬¿ÉÒÔʵÏÖ Java Ô´´úÂë±àÒ룬ʹÄúÄܹ»Ìí¼Ó¶¯Ì¬¹¦ÄÜÀ´À©Õ¹¾²Ì¬Ó¦ÓóÌÐò¡£±¾ÎĽ«Ì½²éjavax.tools°üÖÐÌṩµÄÖ÷ÒªÀ࣬ÒÔJava±í´ïʽ±íʾ¼ÆËãÒ»¸öÊýÖµº¯Êýy=x*x+x¡£¸ü¶àÏêÇéÇë²Î¿¼¡¶Ê¹Óà javax.tools ´´½¨¶¯Ì¬Ó¦ÓóÌÐò¡·ºÍjavax.tools API docs
¡£
complier.CharSequenceCompilerÔ´Â룺
package complier;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;
import javax.tools.JavaCompiler.CompilationTask;
/**
* ±àÒë{@link CharSequence}ÐÎʽµÄÔ´Â룬²¢ÊµÀý»¯£¬·µ»ØÒ»¸öʵÀý¡£<br>
* Ó÷¨Ê¾Àý£¨ÒÔ±àÒëMyInterfaceµÄÒ»¸öʵÏÖÀàΪÀý£©£º
*
* <pre>
* MyInterface instance = null;
* JavaStringCompiler<MyInterface> compiler = new JavaStringCompiler<MyInterface>(null, null);
* try {
* Class<MyInterface> newClass = compiler.compile("com.mypackage.NewClass",
* stringContaininSourceForNewClass, new Class<?>[] { MyInterface.class });
* instance = newClass.newInstance();
* } catch (JavaStringCompilerException ex) {
* ex.printStackTrace();
* } catch (IllegalAccessException ex) {
* ex.printStackTrace();
* }
* instance.someOperation(someArgs);
* </pre>
*/
public class CharSequenceCompiler<T> {
/** ÕæÕýʹÓõıàÒëÆ÷ */
private final JavaCompiler compiler;
private final ClassLoaderImpl classLoader;
/** ±£´æ±àÒëÆ÷±àÒëÖеÄÕï¶ÏÐÅÏ¢ */
private DiagnosticCollector<JavaFileObject> diagnostics;
private final FileManagerImpl javaFileManager;
/** ±àÒë²ÎÊý */
private final List<String> options;
/**
* ¹¹ÔìÒ»¸öеÄʵÀý£¬¸ÃʵÀý³ÖÓÐÖ¸¶¨µÄclassloader
*
* @param loader
*
Ïà¹ØÎĵµ£º
µÚÒ»£º
1.StringÊÇ×î»ù±¾µÄÊý¾ÝÀàÐÍô£¿
´ð£º²»ÊÇ¡£»ù±¾µÄÊý¾ÝÀàÐÍ°üÀ¨£ºbyte,int,char,long,float,double,booleanºÍshort.
java.lang.StringÀàÊÇfinalÀàÐ͵ģ¬Òò´Ë²»¿ÉÒԼ̳ÐÕâ¸öÀ࣬²»ÄÜÐÞ¸ÄÕâ¸öÀà¡£
2.¾²Ì¬±äÁ¿ºÍʵÀý±äÁ¿µÄÇø±ð£¿
´ð£ºstatic i = 10 ;//³£Á¿
&nb ......
Ò»°ãµÄÊÊÓÃÓÚS40µÄJAVAÈí¼þ¶¼¿ÉÒÔ×°ÔÚŵ»ùÑÇ3110cÉÏ,°üÀ¨ÓÎÏ·,µç×ÓÊé,Ó¦ÓÃÈí¼þ ʲôÊÇJAVAÈí¼þÄØ£¿
JavaÊÇÓÉSun΢ϵͳ¹«Ë¾Ëù·¢Õ¹³öÀ´µÄ³ÌÐòÓïÑÔ£¬Ëü±¾ÉíÊÇÒ»ÖÖ¶ÔÏóµ¼Ïò£¨Object-Oriented£©µÄ³ÌÐòÓïÑÔ¡£JAVAÄ¿Ç°ÔÚÊÖ»úÉÏÓ¦ÓÃ×î¶àµÄ¾ÍÊÇJAVAÓÎÏ·¡£
JavaÒ²ºÅ³ÆÊÇÄÜ¿çƽ̨ʹÓõÄÓïÑÔ£¬ÕâÖ÷ÒªÊÇÒòΪJava±¾Éí±»±àÒëÖ®ºó£¬²¢² ......
Ê×ÏÈ£¬Ç¿ÁÒÍƼöÄãÏȲο¼Sun¹Ù·½µÄJava´úÂë/±à³Ì¹æ·¶£º
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
Äã¿ÉÒÔ´òÆÆÒÔÉϵÄÈÎÒ»¹æÔò£¬²»¹ýÒ»¶¨ÒªÓиöºÃÀíÓÉ£¬²¢ÇҼǼÏÂÀ´¡£
ÓÀÔ¶£¬ÓÀÔ¶£¬ÓÀÔ¶²»ÒªÔÚûÓмǼ¶ÑÕ»¸ú×ÙÐÅÏ¢£¨stack trace£©»òÊÇÖØÐÂÅ׳öÒì³£µÄÇé¿öϲ¶»ñÒì³££¬Ë׳Ɠ³ÔµôÒì³£&rd ......
¡¡¡¡ÎªÑ°Çójava´úÂëµÄÐÔÄÜÓÅ»¯£¬´ÓÍøÉÏËѵ½ÀûÓÃfinal¹Ø¼ü×Ö½øÐбàÒëʱinlineÓÅ»¯µÄ·½·¨£¬µ«ÊÇÕæµÄÓÐЧÂð£¿Êµ¼Ê²âÊÔÖз¢ÏÖδ±Ø£¬ÉõÖÁÐÔÄÜÓ°Ïì¾Þ´ó£¬×îÖÕ·ÅÆúÁËʹÓÃfinalÓÅ»¯µÄÏë·¨¡£
¡¡¡¡²âÊÔ»·¾³£ºWindows XP SP2£¬JDK 1.6.0_15-b03£¬Eclipse 3.5 SR1¡£
package test;
public class Test {
public static void main(St ......
BigDecimalÀà
Ë«¾«¶È¸¡µãÐͱäÁ¿double¿ÉÒÔ´¦Àí16λÓÐЧÊý¡£ÔÚʵ¼ÊÓ¦ÓÃÖУ¬ÐèÒª¶Ô¸ü´ó»òÕ߸üСµÄÊý½øÐÐÔËËãºÍ´¦Àí¡£JavaÔÚjava.math°üÖÐÌṩµÄAPIÀàBigDecimal£¬ÓÃÀ´¶Ô³¬¹ý16λÓÐЧλµÄÊý½øÐо«È·µÄÔËËã¡£±í5.7ÖÐÁгöÁËBigDecimalÀàµÄÖ÷Òª¹¹ÔìÆ÷ºÍ·½·¨¡£
±í5.7 BigDecimalÀàµÄÖ÷Òª¹¹ÔìÆ÷ºÍ·½·¨
¹¹ÔìÆ÷ÃèÊö
BigDecimal(in ......