【发布时间】:2015-08-31 16:03:26
【问题描述】:
我面临一个问题,即我需要使用来自同一类中的方法的更新字符串数据。我应该创建一个全局变量吗?如果是这样,我如何将更新的字符串数据放置到全局变量中?下面是我的代码,其中添加了注释以说明更多细节。
public class GenerateSummonPDF
{
public void userdata(String p1, String p2, String p3, String p4)
{
String value1= p1;
String value2= p2;
String value3= p3;
String value4= p4; // all the data here are constantly updating from other class
}
public static void main(String[] args)
{
Document document = new Document();
try
{
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\User\\workspace\\enforement system\\Summon PDF list\\Serial No.pdf"));
document.open();
document.add(new Paragraph("")); //i need to print all the data here from the userdata
document.close();
writer.close();
} catch (DocumentException e)
{
e.printStackTrace();
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
有什么解决办法吗?提前感谢您的帮助。
【问题讨论】:
-
两种方法:1)单例对象; 2) 静态成员
标签: java eclipse string variables global