Skip to content

Tag: types

Why java allows “var” to declare generic variable without specifying type, leading to runtime issue? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 28 days ago. Improve this question Hi: this code get compiled: But with runtime issue. The list local variable is of ArrayList but not any ArrayList<xxx> generic type. Why java let

Why this lambda function does not remember type, in Java? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed last month. Improve this question I

Generic restTemplateExchange with generic responseType

I would like to create a own generic method that calls the In particular I would like that the signature of this generic method to be : I would differentiate what exchange method call according to “responseType” if responseType is Class< T> I call * exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, Class< T> responseType)* if responseType is ParameterizedTypeReference< T>

ANTLR AST visitor that returns different data types

I finished converting the ANTLR CST into an AST and created a specific Visitor<T> interface that allows me to visit all my AST nodes, but the main issue i’m having is that some visits should return different data types, and i’m not sure how to go about this. For example, for simple arithmetics operations i want to return a double

Is there a default type for numbers in Java

If I write something like this Which type has the ’18’? Is it int or byte? Or doesn’t it have a type yet? It can’t be int, because something like this is correct: And this is incorrect: EDIT: I think I found the right part in the spec at Assignment Conversion : The compile-time narrowing of constants means that code