English 中文(简体)
Java:如何将 Str转换成子类数据类型?
原标题:Java: How to convert a String into an subclass data type?
  • 时间:2012-04-25 10:46:11
  •  标签:
  • java

我想将“努力”改为“子”数据类型,如何做到这一点? 还是有可能?

我有一个抽象的班子

A. 公开摘要

A public class SavAcct extends SinAcct

在SavAcct有一个建筑商

public SavAcct(String acctNo, String name, ConsolidateAccount ownerAcct, double lastMonthBal){
        super(acctNo,name,ownerAcct,lastMonthBal);

    }

汇总账户

我想用一个新版的SavAcct,

new SavAcct(array ***,array 和 array[3],Double.parseDouble(array[4])

但它是错误的。 构筑的SavAcct(String, String, Double)没有定义

anyone can help me? pls

问题回答

仅能确保你不再走错的道路,而不必增加一个新建筑商,他们基本上需要打上super(acct no,name, OwnerAcct,lastthBal);就象现有的建筑商一样,为什么你不尝试建立或研究综合建筑。 会计科目:

E.g.

ConsolidateAccount consolidateAccount = new ConcreteConsolidateAccount(array[3]);
new SavAcct(array[1],array[2],consolidateAccount,Double.parseDouble(array[4]);

<代码>ConcreteConsolidateAccount是一个具体类别,延伸ConsolidateAccount

想像更明智的做法。

当然,我并不了解围绕<代码>ConsolidateAccount的逻辑,或者即使它有一个包含String的建筑商,但这只是要给你一个想法,因为你似乎需要把SavAcct所延伸的那类建筑商称作“超级电话”。

您应当有一个具体类别(非抽象类别)来扩大<代码>ConsolidateAccount。

public class ConcreteAccount extends ConsolidateAccount

Then you can use something like this.

ConsolidateAccount ownerAcct = new ConcreteAccount(array[3]);
new SavAcct(array[1],array[2],ownerAcct,Double.parseDouble(array[4]);

在您的具体类别中建立“构造”栏目。

你可以这样做,因为Sting阶级是最终的。 http://www.artima.com

如果你真的想把“强硬”改成另一类物体。 您可以找到三种可能的解决办法:

  1. 创立一名司机,将努力作为论据,并适当转换为制造目的。

  2. 拥有一个工厂方法,即从中获取,其计算参数和回报为目的。

  3. You can have a method which can be used for the same purpose as above.

EDIT

只需指出,“努力”是最后一类,可以在你的申请中加以修改或继承。

public Static SubClass getInstance(String str){
   SubClass obj = new SubClass(); 
   // ***the choice of constructor depends upon how u have created ur class
   //use str to form the SubClass object in following lines 
   return obj;
}

页: 1

SubClass newObj = SubClass.getInstance("String value here");

不可能,“努力”是最终的。

The java.lang.String class is final, so there s no way you can extend it. You could at most wrap it.

您有一系列的长处,而您的施工者则在第三位职位上打电话到<条码>。 您需要根据第三版<编码>String,即<编码>查询。 没有任何细节可以帮助你如何做到这一点。 另外,你正在将阵列从1个指数化。 射线为零。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签