I have implemented a hashmap in a method (call it method a) and in that method a I have called another method (call it method b) from which I transfer the hashmap built in method a to method b. Problem is that when I try to get the values of hmap in method b, it didn’t allow me to write the statement for that.
In class analyzer I have 2 methods method a and method b. I have called a method b from the statement below:
analyzer v=new analyzer();
v.b(hMap1, 1);
In method b, I try to obtain the values of hmap1 but it does not allow me to write:
public HashMap b(HashMap x,int i)
{
System.out.println( x.get("6").dstip);
}
It does not allow me to write .dstip where as when I write this printing
statement in method a, it gives the results on console. I have made the hashmap public, i dont know then why its not allowing me to write the desired statement.
Your HashMap is untyped, so invoking the
getmethod on it returns instances of typeObject. There is no public property onObjectcalleddstip, so your compilation fails. Of course your code snippet would work if Java was dynamically typed, but thats totally off topic.You should declare and pass around your
HashMapwith an appropriate parametized type. Say:On a side note, your Java code doesn’t follow best practices for naming or property access.