Jump to content

Public Boolean


Recommended Posts

I am new to Java and I want to create a public boolean in one Public class and set it with an expression, then I want to use that in all packages. I know that I need to sent a Pulic boolean like such public booealn cs1500Job;then import that package in all the other packages but it doesn't seem to work can it be done and if so how? main class code

package com.nortel.nds.server.common;...........public class DLINEINVBuilder extends DLINEBuilder{    public boolean CS1500Job;............    public DLINEINVBuilder(AbstractModel oldModel, AbstractModel newModel)    {            super(oldModel, newModel);                Properties convProps = sourceModel.getConversionProperties();        [b]CS1500Job[/b] = YES.equals(convProps.getProperty(PROCCHOICES+CS1500_Job));........   if (![b]CS1500Job[/b]) {            this.tableIDXXREF   = (AbstractTable) targetModel.getTable("IDXXREF");        }

Other Class code.

public class DLINEINVBasher extends BaseBasher{ ................. public List<String> process() throws TransformerException    {                ArrayList<String> results = new ArrayList<String>();  if ([b]CS1500Job[/b]) {            System.out.println("Line 96");                  if (bashMode == null) {            results.add("No Bash Mode was selected!");            return results;        }.............

Link to comment
Share on other sites

I'm not really sure what you are going for here. What would be the purpose of that boolean? Is it supposed to have the same value for all instances of DLINEINVBuilder objects? Or are you wanting each instance to have its own value?I don't remember Java very well, but I do know C# which is similar.If you want the same value for every instance of DLINEINVBuilder, then you'd want to make that member static: C#

public class DLINEINVBuilder : DLINEBuilder{	public static bool CS1500Job = true;	...

Then, to use that value in another class:C#

public class DLINEINVBasher : BaseBasher{	public void test()	{		if (DLINEINVBuilder.CS1500Job)		{			...		}	}}

If, on the other hand, you want different instances of the DLINEINVBuilder object to have different values for CS1500Job, then, whenever you want to use that property, you would have to instantiate the appropriate DLINEINVBuilder object and reference that value through it.

Link to comment
Share on other sites

The best way to reference a variable in multiple classes is to create getter and setter methods for the variable and extend the original class to whatever classes need to use it.The function you would need to get/set the variable would be something like

public void setCS1500Job(boolean CS1500Job){	this.CS1500Job = CS1500Job;}public boolean getCS1500Job(){	 return CS1500Job;}

Then in the classes that need to use the variable you'll need something like

ClassName name = new ClassName();name.getCS1500Job();

If you want to save that value for a specific object then you'll need some sort of database to keep it in and then automatically read it from the db when the object is created (maybe put an id in the constructor) and then write it back to the db before the object is destroyedI don't know if that helps since I don't really see exactly what you are going for. Give us more information.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...