IntelliJ Community . GenericsFAQ

 
GenericsFAQ 

HOME INDEX SEARCH CHANGES GO  

Generics guide for Pallada (IDEA 4.1)

For Aurora (IDEA 4.0) look at GenericsAuroraFAQ

Here is a simple How To Guide to get started with java generics. Please feel free to make any corrections or additions that you think are necessary to make the transition easier.

Installation

  1. use the wizard in IDEA for that. It can be found in the menu Tools/Set Up JSR014 Implementation. We will call the directory where you installed the generics JSR14_HOME.
  2. As of 2.4, you need to copy the classes of gjc-rt.jar into collect.jar. Do this with the collect.jar inside IDEA_HOME/lib/generics

Set up an IDEA project

  1. Open the Settings (Ctrl-Alt-S)
  2. Select the Paths properties
  3. In the Paths tab add IDEA_HOME/lib/generics/collect.jar and select java 1.5
     
    Settings/Paths/Libraries Tab.jpg
     
  4. In the Order/Export tab, put collect.jar first (before the JDK)
     
    Settings/Paths/Order Tab.jpg
     
  5. Select the Compiler properties
  6. Select the option Use generics-enabled compiler and enter -target jsr14 in the _Additional command line arguments
     
    Settings/Compiler.jpg
     
  7. Restart IDEA

Set up Ant

Using JSR Adapter for compiling

  1. Add a property named jsr14.home that points to JSR14_HOME
    <property name="jsr14.home" value="<<JSR14_HOME>>"/>
  2. Add collect.jar in first in any compilation classpath
  3. Download the compiler adapter generously donated by Cortex eBusiness (maker of clover one of the greatest java coverage tool) here or use the cached version here and save it either in your project or your ant install
  4. Add jsr14adapter-1.2.jar to your Ant classpath. In IDEA:
    1. Go to the Ant tool window/Properties
       
    2. Add jsr14adapter-1.2.jar to the Additional Classpath
       
  5. Change your javac target to add the following attributes
    <javac destdir="${dir.build.classes}"
             source="1.5"
             compiler="com.cortexeb.Jsr14CompilerAdapter"
             srcdir="${dir.plugin.util.src}:${dir.src}:${dir.additional.src}">
             <classpath refid="compile.classpath"/>
          </javac>
  6. Add this to your junit task
    <junit fork="yes">
    ...
    <jvmarg value="-Xbootclasspath/p:${jsr14.home}/gjc-rt.jar"/> </junit>
  7. You are set

Using standard javac ANT task for compiling

You can compile generics code by javac ANT task:

  <javac
    fork="yes"
    includejavaruntime="yes"
    destdir="${project.classes}"
    bootclasspath="${generics.home}/collect.jar"
    classpathref="project.classpath"
    debug="on"
    source="1.5"
    >
    <compilerarg value="-J-Xbootclasspath/p:${generics.home}/gjc-rt.jar"/>
    <src path="${project.src}"/>
    <include name="**/*.java"/>
  </javac>

Using sinjdoc tool for JavaDoc generation

You must have sinjdoc installed. For generation javadocs you may use follow script:

  <fileset dir="${project.src}" id="project.src.java">
    <include name="**/*.java" />
  </fileset>
  <pathconvert pathsep=" " property="project.src.files" refid="project.src.java"/>

  <java jar="${sinjdoc.home}/sinjdoc.jar" fork="true">
    <jvmarg line="-Xbootclasspath/p:${generics.home}/gjc-rt.jar"/>
    <classpath refid="project.classpath" />
    <arg value="-protected" />
    <arg value="-author" />
    <arg value="-version" />
    <arg value="-use" />
    <arg value="-source" />
    <arg value="1.5" />
    <arg value="-d" />
    <arg value="${project.build}/${project.name}/docs/api" />
    <arg value="-sourcepath" />
    <arg value="${project.src}" />

    <arg line="${project.src.files}" />
  </java>

Tips

General info on java 1.5 generics support

Using 1.5 class with a 1.4 VM

javadoc and javap for generics

Known issues

OutOfMemoryError using Generics

See http://www.intellij.net/tracker/idea/viewSCR?publicId=14522 for more detail.

e d i t a t t a c h r e f - b y d i f f s m o r e
Have ideas, requests, problems regarding this site? Send feedback.
Copyright © 2000-2003 by the contributing authors. All materials at intellij.org are the property of the contributing authors.