java - Identifier Expected Error Hash Table -


i'm having identifier expected error in block of code:

 @suppresswarnings({"rawtypes","unchecked"})     thelists = new list<anytype>[ nextprime( 2 * thelists.length ) ]; for( int j = 0; j < thelists.length; j++ )         thelists[ j ] = new linkedlist<>( ); 

the compiler says there should identifier after "thelists" , before =. identifier? how fix this?

this full method:

      private void rehash( ) {     list<anytype> [ ]  oldlists = thelists;          // create new double-sized, empty table @suppresswarnings({"rawtypes","unchecked"})     thelists = new list<anytype>[ nextprime( 2 * thelists.length ) ]; for( int j = 0; j < thelists.length; j++ )         thelists[ j ] = new linkedlist<>( );          // copy table on     currentsize = 0;     for( list<anytype> list : oldlists )         for( anytype item : list )             insert( item ); } 

i removed suppress warnings body , put in constructor, still says identifier expected:

    public hashtable( int size )  {     @suppresswarnings("unchecked") thelists =  (list<anytype>[]) new list<?>[nextprime(2 * thelists.length)];  for( int = 0; < thelists.length; i++ )         thelists[ ] = new arraylist<>( );  } 

an annotation can appear in following locations

  • method declarations (including elements of annotation types)
  • constructor declarations
  • field declarations (including enum constants)
  • formal , exception parameter declarations
  • local variable declarations (including loop variables of statements , resource variables of try-with-resources statements)

you're trying apply here

@suppresswarnings({"rawtypes","unchecked"}) thelists = new list<anytype>[ nextprime( 2 * thelists.length ) ]; 

which not declaration, assignment expression. won't work. instead annotate method containing code.

once that, you'll error cannot create generic array. there many questions , answers around. read those.

you can do

thelists = (list<anytype>[]) new list<?>[nextprime(2 * thelists.length)]; 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -