1

i have been working on converting a python code to java which is related to my research work. i just cannot understand how to convert python type "any" to java, as we dont need to write data types in python but in java its necessary. i need your kind suggestions on that

i am trying to read data from a file and putting it into different lists, as python can automatically handle the datatypes of that data, is there any similar method to do it in java.

covMatrix = savedata[1]

covMatrix and savedata both have inferred type any at initial stage, i want to write it in java but there i have to write the data type. as i told you i want to know that is there any method in java to automatically detect the data type of data.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114

3 Answers3

0

I think in Java 10 you can use the var keyword to get local variable type inference. I've never had to use it personally though so I'm not sure how you would go about using it in your context. Hopefully this gets you moving in the right direction though.

Have a look at this question, as it may direct you to a solution you're looking for. Is there auto type inferring in Java?

LockieR
  • 370
  • 6
  • 19
0

Use the var identifier, it infers the type for you.

var covMatrix = savedata[1];

Note that it only appeared in Java 10, so if you are using an older version of Java it's not possible to infer the type and you have to write it manually.

Ricola
  • 2,621
  • 12
  • 22
-1

You can use Object, it is basically Java's Any

e.g. Object covMatrix = savedata[1];

wilmol
  • 1,429
  • 16
  • 22
  • That would not infer the type. – Ricola Jul 24 '19 at 14:18
  • Never said it would. The OP says ```i want to write it in java but there i have to write the data type```. This provides him with a solution for older versions of Java. – wilmol Jul 25 '19 at 06:58