Results 1 to 2 of 2

Thread: Quick Question - how can I make this type safe?

  1. #1
    Join Date
    May 2009
    Posts
    246

    Default Quick Question - how can I make this type safe?

    How can I make this type safe?

    Code:
    	public List<Module> findAllWithAdmin( long adminId ) {
    		return (List<Module>) sessionFactory.getCurrentSession().createQuery(
    			"from Module module where module.admin.id = :adminId" )
    			.setParameter( "adminId", adminId )
    			.list();
    	}
    Last edited by mystic; May 10th, 2009 at 02:02 AM.

  2. #2
    Join Date
    May 2008
    Location
    Silicon Valley, CA
    Posts
    139

    Default

    Clarify which part you think is not "type safe"?

    ("from Module ...").list() will return a List<Module>
    so it is "type safe" although the Java compiler cannot prove this.

    If you want to stop the compiler from barking, consider
    @SuppressWarnings("unchecked")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •