Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suspect the simplest approach would be to create a trivial subclass of <code>TreeSet</code> that provides a two-argument constructor:</p> <pre><code>public class MyTreeSet&lt;T&gt; extends TreeSet&lt;T&gt; { public MyTreeSet(Comparator&lt;? super T&gt; cmp, Collection&lt;? extends T&gt; coll) { super(cmp); addAll(coll); } } </code></pre> <p>and use this as the type of your bean, passing both the comparator and the initial values as <code>&lt;constructor-arg&gt;</code> values.</p> <pre><code>&lt;bean id="studentSet" class="com.example.MyTreeSet"&gt; &lt;constructor-arg index="0"&gt; &lt;bean class="com.example.MyComparator" /&gt; &lt;/constructor-arg&gt; &lt;constructor-arg index="1"&gt; &lt;list&gt; &lt;ref bean="student1" /&gt; &lt;ref bean="student2" /&gt; &lt;ref bean="student3" /&gt; &lt;/list&gt; &lt;/constructor-arg&gt; &lt;/bean&gt; </code></pre> <p>Or instead of a subclass of <code>TreeSet</code> you could write your own <code>FactoryBean</code>.</p> <p>To do it without writing any additional code you could use a second bean definition to do the adding</p> <pre><code>&lt;bean id="studentSet" class="java.util.TreeSet"&gt; &lt;constructor-arg&gt; &lt;bean class="com.example.MyComparator" /&gt; &lt;/constructor-arg&gt; &lt;/bean&gt; &lt;bean id="studentSetFiller" factory-bean="studentSet" factory-method="addAll"&gt; &lt;constructor-arg&gt; &lt;list&gt; &lt;ref bean="student1" /&gt; &lt;ref bean="student2" /&gt; &lt;ref bean="student3" /&gt; &lt;/list&gt; &lt;/constructor-arg&gt; &lt;/bean&gt; </code></pre> <p>but then any other bean into which you inject <code>studentSet</code> needs an additional <code>depends-on="studentSetFiller"</code> to make sure the set is populated before the target bean tries to use it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload