Skip to main content
gamedev.net
🔒 Locked

Java equivalent for the C++ command..

Started by uber_n00b 4 replies 350+ views
Original Post
uber_n00b
uber_n00b
extern? Is there a Java equivalent or is it implied in Java (not likely). FYI in case people in Java don''t know what I''m talking about, if one has two c++ files, cpp1 and cpp2, if ''int a'' is declared globally in cpp1, you can use/get the values of that same variable in cpp1 but in cpp2 by declaring at the top ''extern int a''.
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
Sneftel
Sneftel
Java doesn''t have global variables. And even if it did, since unlike C++ it doesn''t have to deal with braindead compilers and linkers, extern wouldn''t be needed.


"Sneftel is correct, if rather vulgar." --Flarelocke
Rickmeister
Rickmeister
Nope. Not as I know of. And globals are a big no-no!

"Imagination is more important than knowledge..." Albert Einstein
Arild Fines
Arild Fines
A "global" in Java would be a static public variable:

public class Globals
{
public static int global = 42;
}


This can now be accessed from anywhere as Globals.global = 84;




--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
uber_n00b
uber_n00b
Thanks that was Arild. I hope that works across files too as in values affected in one file will be represented in another. It''s complicated, but I''m trying to convert a 3000 line C++ OpenGL program to Java, and well, it''s a real learning process.
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
Matei
Matei
It certainly does work accross files, as long as you make the variable public static. Java compilers only compile individual classes to an intermediate format, which the virtual machine / JIT then loads, resolving references between them while doing this. I''d suggest getting a good book on Java and/or making some simple practice programs to get an idea of the things it can and can''t do.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.