Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » im getting "var cannot be resolved to a type" error(var error eclipse)
im getting "var cannot be resolved to a type" error [message #1826508] Sun, 26 April 2020 06:46 Go to next message
Fort vin is currently offline Fort vinFriend
Messages: 2
Registered: April 2020
Junior Member
hey guys! i just started java and my first problem occured, but i guess there is something to be fixed in compiler. im getting a var error. for some reason the compiler cannot recognize var

ive been googling and ive noticed that it is a common "issue"

any one here who can help me out? im using eclipse 4.15.0


public class VarDemo2 {

ppublic class VarDemo2 {
public static void main(String args[]) {
var mc = new MyClass(10);
System.out.println("Value of i in mc is " +
System.out.println("Value of i in mc is now "
+ mc.get());

Error: Exception in thread "main" java.lang.Error: Unresolved compilation problem:

var cannot be resolved to a type
at VarDemo2.main([]

[Updated on: Mon, 15 February 2021 14:52] by Moderator

Report message to a moderator

Re: im getting "var cannot be resolved to a type" error [message #1826535 is a reply to message #1826508] Sun, 26 April 2020 18:07 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1832
Registered: July 2009
Senior Member
Some observations:

Your code has a few extra errors: duplicate class header, typo in "ppublic".

The message that you are seeing when you try to run the program should be immediately visible as compile errors (in the editor and also in the Problems view). If you see such compile errors, you should fix them, before trying to run the program :)

Whether or not the compile error is raised, depends on your Java compliance settings. 'var' was introduced in Java 10, so when you configure your project for Java 8, e.g., then 'var' is indeed not legal instead of a type.
Previous Topic:Character.isIdentifierIgnorable
Next Topic:Breakpoint in debugged application doesn't show source file, after upgrade to 2020-03
Goto Forum:

Current Time: Sun May 16 11:31:09 GMT 2021

Powered by FUDForum. Page generated in 0.02451 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top