⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collectionconstruction.html

📁 ONGL学习的好书,介绍ONGL的相关知识
💻 HTML
字号:
<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Collection Construction</title><link href="../docbook.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.65.0" name="generator"><link rel="home" href="index.html" title="OGNL Language Guide"><link rel="up" href="basicExpressions.html" title="Chapter&nbsp;4.&nbsp;Expressions"><link rel="previous" href="chainedSubexpressions.html" title="Chained Subexpressions"><link rel="next" href="projection.html" title="Projecting Across Collections"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">Collection Construction</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="chainedSubexpressions.html"><img src="../images/navigation/prev.gif" alt="Prev"></a>&nbsp;</td><th align="center" width="60%">Chapter&nbsp;4.&nbsp;Expressions</th><td align="right" width="20%">&nbsp;<a accesskey="n" href="projection.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="collectionConstruction"></a>Collection Construction</h2></div></div><div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="listConstruction"></a>Lists</h3></div></div><div></div></div><p>To create a list of objects, enclose a list of expressions in curly braces. As with method arguments, these expressions cannot use the comma operator unless it is enclosed in parentheses. Here is an example:</p><pre class="programlisting">name in { null,"Untitled" }</pre><p>This tests whether the <tt class="varname">name</tt> property is <tt class="constant">null</tt> or equal to <tt class="constant">"Untitled"</tt>.</p><p>The syntax described above will create a instanceof the <tt class="classname">List</tt> interface. The exact subclass is not defined.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="nativeArrayConstruction"></a>Native Arrays</h3></div></div><div></div></div><p>Sometimes you want to create Java native arrays, such as <span class="type">int[]</span> or <span class="type">Integer[]</span>. <span class="acronym">OGNL</span> supports the creation of these similarly to the way that constructors are normally called, but allows
                initialization of the native array from either an existing list or a given size of the array.</p><pre class="programlisting">new int[] { 1, 2, 3 }</pre><p>This creates a new <span class="type">int</span> array consisting of three integers 1, 2 and 3.</p><p>To create an array with all <tt class="constant">null</tt> or <tt class="constant">0</tt> elements, use the alternative size constructor</p><pre class="programlisting">new int[5]</pre><p>This creates an <span class="type">int</span> array with 5 slots, all initialized to zero.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="mapConstruction"></a>Maps</h3></div></div><div></div></div><p>Maps can also be created using a special syntax.</p><pre class="programlisting">#{ "foo" : "foo value", "bar" : "bar value" }</pre><p>This creates a Map initialized with mappings for <tt class="literal">"foo"</tt> and <tt class="literal">"bar"</tt>.</p><p>Advanced users who wish to select the specific Map class can specify that class before the opening curly brace</p><pre class="programlisting">#@java.util.LinkedHashMap@{ "foo" : "foo value", "bar" : "bar value" }</pre><p>The above example will create an instance of the JDK 1.4 class <tt class="classname">LinkedHashMap</tt>, ensuring the the insertion order of the elements is preserved.</p></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="chainedSubexpressions.html"><img src="../images/navigation/prev.gif" alt="Prev"></a>&nbsp;</td><td align="center" width="20%"><a accesskey="u" href="basicExpressions.html"><img src="../images/navigation/up.gif" alt="Up"></a></td><td align="right" width="40%">&nbsp;<a accesskey="n" href="projection.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr><tr><td valign="top" align="left" width="40%">Chained Subexpressions&nbsp;</td><td align="center" width="20%"><a accesskey="h" href="index.html"><img src="../images/navigation/home.gif" alt="Home"></a></td><td valign="top" align="right" width="40%">&nbsp;Projecting Across Collections</td></tr></table></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -