Generic Map Parameter java -


i having lot of methods of type:

public static list<eduusers> getdetails(class c, map<string, integer> params) {         list<eduusers> details = null;         session session = hibernateutil.getsessionfactory().opensession();         transaction tx = null;         try {             tx = session.begintransaction();             criteria cr = session.createcriteria(c);             (map.entry<string, integer> entry : params.entryset()) {                 cr.add(restrictions.eq(entry.getkey(), entry.getvalue()));             }             details = cr.list();             tx.commit();         } catch (exception asd) {             log.debug(asd.getmessage());             if (tx != null) {                 tx.commit();             }         } {             session.close();         }         return details;     } 

i trying have generic method them , have written far:

 public static <t> list<t> getdetails(class<t> c, class<t> b) {         list<t> details = null;         session session = hibernateutil.getsessionfactory().opensession();         transaction tx = null;         try {             tx = session.begintransaction();             criteria cr = session.createcriteria(c);             //am stuck on iteration of map class t b             details = cr.list();             tx.commit();         } catch (exception asd) {             log.debug(asd.getmessage());             if (tx != null) {                 tx.rollback();             }         } {             session.close();         }         return details;     } 

how put generic map onto method?

edit: map values type can change need able put not integers strings , other types

to use generic map should define method allow map type of object pass in value place of map.

your new method should getdetails(class<t> c,map<string,?> params)

and map entry iterator should below:

for (map.entry<string, object> entry : params.entryset()) {                 cr.add(restrictions.eq(entry.getkey(), entry.getvalue()));  } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -