aboutsummaryrefslogtreecommitdiffstats
path: root/docs/adk15notebook/autoboxing.adoc
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2022-01-08 11:50:55 +0700
committerAlexander Kriegisch <Alexander@Kriegisch.name>2024-01-06 10:09:11 +0100
commitd4a6906b3012fac6e4dbaca5854fc59ba0d67e47 (patch)
treec78540555837c12cfaef7f9cc95842668a3ee7f9 /docs/adk15notebook/autoboxing.adoc
parent9735e858af48ff0bce152ea489800a86a151b08d (diff)
downloadaspectj-d4a6906b3012fac6e4dbaca5854fc59ba0d67e47.tar.gz
aspectj-d4a6906b3012fac6e4dbaca5854fc59ba0d67e47.zip
Rename '*GuideDB' directories to their actual HTML site target names
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'docs/adk15notebook/autoboxing.adoc')
-rw-r--r--docs/adk15notebook/autoboxing.adoc80
1 files changed, 80 insertions, 0 deletions
diff --git a/docs/adk15notebook/autoboxing.adoc b/docs/adk15notebook/autoboxing.adoc
new file mode 100644
index 000000000..fa3842950
--- /dev/null
+++ b/docs/adk15notebook/autoboxing.adoc
@@ -0,0 +1,80 @@
+[[autoboxing]]
+== Autoboxing and Unboxing
+
+[[boxing-inJava5]]
+=== Autoboxing and Unboxing in Java 5
+
+Java 5 (and hence AspectJ 1.5) supports automatic conversion of
+primitive types (`int`, `float`, `double` etc.) to their object equivalents
+(`Integer`, `Float`, `Double` etc.) in assignments and method and constructor
+invocations. This conversion is know as autoboxing.
+
+Java 5 also supports automatic unboxing, where wrapper types are
+automatically converted into their primitive equivalents if needed for
+assignments or method or constructor invocations.
+
+For example:
+
+[source, java]
+....
+int i = 0;
+i = new Integer(5); // auto-unboxing
+Integer i2 = 5; // autoboxing
+....
+
+[[autoboxing-in-aspectj5]]
+=== Autoboxing and Join Point matching in AspectJ 5
+
+Most of the pointcut designators match based on signatures, and hence
+are unaffected by autoboxing. For example, a call to a method
+
+[source, java]
+....
+public void foo(Integer i);
+....
+
+is _not_ matched by a pointcut `call(void foo(int))` since the signature
+declares a single `Integer` parameter, not an `int`.
+
+The `args` pointcut designator is affected by autoboxing since it
+matches based on the runtime type of the arguments. AspectJ 5 applies
+autoboxing and unboxing in determining argument matching. In other
+words, `args(Integer)` will match any join point at which there is a
+single argument of type `Integer` or of type `int`.
+
+* `args(Integer)` and `args(int)` are equivalent
+* `args(Float)` and `args(float)` are equivalent
+* `args(Double)` and `args(double)` are equivalent
+* `args(Short)` and `args(short)` are equivalent
+* `args(Byte)` and `args(byte)` are equivalent
+* `args(Long)` and `args(long)` are equivalent
+* `args(Boolean)` and `args(boolean)` are equivalent
+
+Autoboxing and unboxing are also applied when binding pointcut or advice
+parameters, for example:
+
+[source, java]
+....
+pointcut foo(int i) : args(i);
+
+before(Integer i) : foo(i) {
+ // ...
+}
+....
+
+[[autoboxing-and-method-dispatch]]
+=== Inter-type method declarations and method dispatch
+
+Autoboxing, unboxing, and also varargs all affect the method dispatch
+algorithm used in Java 5. In AspectJ 5, the target method of a call is
+selected according to the following algorithm:
+
+[arabic]
+. Attempt to locate a matching method or inter-type declared method
+without considering autoboxing, unboxing, or vararg invocations.
+. If no match is found, try again considering autoboxing and unboxing.
+. Finally try again considering both autoboxing, unboxing, and varargs.
+
+One consequence is that a directly matching inter-type declared method
+will take precedence over a method declared locally in the target class
+but that only matches via autoboxing.