Changeset 13624
- Timestamp:
- 10/10/11 18:33:50 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/doc/manual/abcl.tex
r13623 r13624 7 7 \title{A Manual for Armed Bear Common Lisp} 8 8 \date{October 2, 2011} 9 \author{Mark~Evenson, Erik~Huelsmann, Alessio~Stall o, Ville~Voutilainen}9 \author{Mark~Evenson, Erik~Huelsmann, Alessio~Stalla, Ville~Voutilainen} 10 10 11 11 \maketitle … … 93 93 \begin{itemize} 94 94 \item Missing statement of conformance in accompanying documentation 95 \item The generic function sig atures of the DOCUMENTATION symbol do95 \item The generic function signatures of the DOCUMENTATION symbol do 96 96 not match the CLHS. 97 97 \end{itemize} … … 133 133 apply to strings, integers and floats. Other values need to be converted 134 134 to their Java equivalents by the programmer before calling the Java 135 object method. 135 object method. Java values returned to Lisp are also generally converted 136 back to their Lisp counterparts. Some operators make an exception to this 137 rule and do not perform any conversion; those are the ``raw'' counterparts 138 of certain FFI functions and are recognizable by their name ending with 139 \code{-RAW}. 136 140 137 141 \subsection{Lowlevel Java API} … … 172 176 Once you have a reference to the method, you can call it using \code{JAVA:JCALL}, 173 177 which takes the method as the first argument. The second argument is the 174 object instance to call the method on . Any remaining parameters are used175 as the remaining arguments for the call.178 object instance to call the method on, or \code{NIL} in case of a static method. 179 Any remaining parameters are used as the remaining arguments for the call. 176 180 177 181 \subsubsection{Calling Java object methods: dynamic dispatch} … … 184 188 select the best matching method and dispatch the call. 185 189 186 % ###TODO document ``intended class'' 190 \subsubsection{Dynamic dispatch: caveats} 191 192 Dynamic dispatch is performed by using the Java reflection API. Generally 193 it works fine, but there are corner cases where the API does not correctly 194 reflect all the details involved in calling a Java method. An example is 195 the following Java code: 196 197 \begin{listing-java} 198 ZipFile jar = new ZipFile("/path/to/some.jar"); 199 Object els = jar.entries(); 200 Method method = els.getClass().getMethod("hasMoreElements"); 201 method.invoke(els); 202 \end{listing-java} 203 204 even though the method \code{hasMoreElements} is public in \code{Enumeration}, 205 the above code fails with 206 207 \begin{listing-java} 208 java.lang.IllegalAccessException: Class ... can 209 not access a member of class java.util.zip.ZipFile$2 with modifiers 210 "public" 211 at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65) 212 at java.lang.reflect.Method.invoke(Method.java:583) 213 at ... 214 \end{listing-java} 215 216 because the method has been overridden by a non-public class and the 217 reflection API, unlike javac, is not able to handle such a case. 218 219 While code like that is uncommon in Java, it is typical of ABCL's FFI 220 calls. The code above corresponds to the following Lisp code: 221 222 \begin{listing-lisp} 223 (let ((jar (jnew "java.util.zip.ZipFile" "/path/to/some.jar"))) 224 (let ((els (jcall "entries" jar))) 225 (jcall "hasMoreElements" els))) 226 \end{listing-lisp} 227 228 except that the dynamic dispatch part is not shown. 229 230 To avoid such pitfalls, all Java objects in ABCL carry an extra 231 field representing the ``intended class'' of the object. That is the class 232 that is used first by \code{JAVA:JCALL} and similar to resolve methods; 233 the actual class of the object is only tried if the method is not found 234 in the intended class. Of course, the intended class is always a superclass 235 of the actual class - in the worst case, they coincide. The intended class 236 is deduced by the return type of the method that originally returned 237 the Java object; in the case above, the intended class of \code{ELS} 238 is \code{java.util.Enumeration} because that's the return type of 239 the \code{entries} method. 240 241 While this strategy is generally effective, there are cases where the 242 intended class becomes too broad to be useful. The typical example 243 is the extraction of an element from a collection, since methods in 244 the collection API erase all types to \code{Object}. The user can 245 always force a more specific intended class by using the \code{JAVA:JCOERCE} 246 operator. 187 247 188 248 % \begin{itemize} … … 202 262 \subsubsection{Parameter matching for FFI dynamic dispatch} 203 263 204 205 ... 264 The algorithm used to resolve the best matching method given the name 265 and the arguments' types is the same as described in the Java Language 266 Specification. Any deviance should be reported as a bug. 267 268 % ###TODO reference to correct JLS section 206 269 207 270 \section{Lisp from Java}
Note: See TracChangeset
for help on using the changeset viewer.