新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     >>计算机科学论坛<<     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 软件工程、需求工程、系统工程,UML、MDA、模型驱动开发,面向对象软件工程、面向目标软件成功、面向场景的设计、敏捷
    [返回] 计算机科学论坛计算机技术与应用『 软件工程论坛 』 → 面向对象构造关于reference的静态构造异常[含我的回帖] 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 6315 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 面向对象构造关于reference的静态构造异常[含我的回帖] 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     pennyliang 帅哥哟,离线,有人找我吗?白羊座1979-4-7
      
      
      威望:8
      等级:大二期末(C++考了100分!)
      文章:266
      积分:1911
      门派:Lilybbs.net
      注册:2005/3/11

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给pennyliang发送一个短消息 把pennyliang加入好友 查看pennyliang的个人资料 搜索pennyliang在『 软件工程论坛 』 的所有贴子 引用回复这个贴子 回复这个贴子 查看pennyliang的博客楼主
    发贴心情 面向对象构造关于reference的静态构造异常[含我的回帖]

    1. LiuPu
    12月29日 上午10时34分   显示选项

    新闻论坛:comp.object
    发件人: "LiuPu" <Liup...@gmail.com> - 查找此作者的帖子  
    日期:28 Dec 2005 18:34:19 -0800
    当地时间:2005年12月29日(星期四) 上午10时34分  
    主题:I can't explain this
    回复 | 答复作者 | 转发 | 打印 | 显示个别帖子 | 显示原始邮件 | 报告滥用行为  

    // A.java
    public abstract class A{
      public String str = "AAA";


    }


    // B.java
    public B extends A{
      A a = new B();
      public static void main(String[] args){
        A b = new B();
      }


    }


    When I use "java B" , the error "java.lang.StackOverflowError" appears.
    I can't explain this.

    回复
                  
          


       2. iamfrac...@hotmail.com
    12月29日 下午4时37分   显示选项

    新闻论坛:comp.object
    发件人: iamfrac...@hotmail.com - 查找此作者的帖子  
    日期:29 Dec 2005 00:37:01 -0800
    当地时间:2005年12月29日(星期四) 下午4时37分  
    主题:Re: I can't explain this
    回复 | 答复作者 | 转发 | 打印 | 显示个别帖子 | 显示原始邮件 | 报告滥用行为  


    LiuPu skrev:

    > // A.java
    > public abstract class A{
    >   public String str = "AAA";
    > }
    > // B.java
    > public B extends A{
    >   A a = new B();
    >   public static void main(String[] args){
    >     A b = new B();
    >   }
    > }

    > When I use "java B" , the error "java.lang.StackOverflowError" appears.
    > I can't explain this.

    Hej!

    Firstly, this has nothing to do with inheritence; you can see the
    problem in its simplest form in the following class:


    class Test {
        Test anotherTest = new Test();


        public static void main(String[] args) {
            Test test = new Test();
        }

    }


    The problem is cause because every Test object is creating another Test
    object, leading to an attempt to create an infinite amount of Test
    objects.

    So, in the main() method, the JVM pushes the execution context onto the
    stack when it calls the Test() constructor; but this will first attempt
    to initialise all field variables in Test, and the only field variable
    is another Test object. When this Test() constructor is called, yet
    another execution context must be pushed onto the stack, etc.


    In the end, the stack is filled and the JVM says goodbye.


    If you actually want your  B object to hold a reference to another A
    object, then you'll have to declare the field variable as equal to
    null, and add the appropriate referenced A object after the B object is
    initialised (e.g., with a setter method).


    .ed


    --
    www.EdmundKirwan.com - Home of The Fractal Class Composition.


    回复
                  
          


       3. Penny Liang
    12月29日 下午7时46分   显示选项

    新闻论坛:comp.object
    发件人: "Penny Liang" <pennyliang...@software.nju.edu.cn> - 查找此作者的帖子  
    日期:Thu, 29 Dec 2005 19:46:08 +0800
    当地时间:2005年12月29日(星期四) 下午7时46分  
    主题:Re: I can't explain this
    回复 | 答复作者 | 转发 | 打印 | 显示个别帖子 | 显示原始邮件 | 报告滥用行为  

    for extends A, B has a static relation with A because of inheritance,
    for contain a reference of A,B has a dynamic relation with A, because of
    reference.


    let's see the construciton of  B
    create A(for extends)
    create B(for reference)
         create A(for extends)
         create B(for reference)
             ........
             ........


    the StackOverflowError occures because of the construction function of B


    --
    Thanks & Regards,
    Penny Liang
    Email:jackli...@vip.sina.com;pennyliang...@software.nju.edu.cn


    "LiuPu" <Liup...@gmail.com> ????
    news:1135823659.216804.243720@o13g2000cwo.googlegroups.com...

    - 隐藏被引用文字 -
    - 显示引用的文字 -

    > // A.java
    > public abstract class A{
    >   public String str = "AAA";
    > }
    > // B.java
    > public B extends A{
    >   A a = new B();
    >   public static void main(String[] args){
    >     A b = new B();
    >   }
    > }

    > When I use "java B" , the error "java.lang.StackOverflowError" appears.
    > I can't explain this.

    回复
                  
          


       4. LiuPu
    12月30日 下午1时36分   显示选项

    新闻论坛:comp.object
    发件人: "LiuPu" <Liup...@gmail.com> - 查找此作者的帖子  
    日期:29 Dec 2005 21:36:42 -0800
    当地时间:2005年12月30日(星期五) 下午1时36分  
    主题:Re: I can't explain this
    回复 | 答复作者 | 转发 | 打印 | 显示个别帖子 | 显示原始邮件 | 报告滥用行为  

    Thank you for your answers. Now I know the problem and its answer.


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/12/31 11:57:00
     
     jiachong 帅哥哟,离线,有人找我吗?
      
      
      威望:4
      等级:
      文章:227
      积分:1515
      门派:IEEE.ORG.CN
      注册:2004/11/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给jiachong发送一个短消息 把jiachong加入好友 查看jiachong的个人资料 搜索jiachong在『 软件工程论坛 』 的所有贴子 引用回复这个贴子 回复这个贴子 查看jiachong的博客2
    发贴心情 
    感觉还是iamfrac...@hotmail.com 说得对,与继承无关吧,我认为
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/12/31 12:28:00
     
     pennyliang 帅哥哟,离线,有人找我吗?白羊座1979-4-7
      
      
      威望:8
      等级:大二期末(C++考了100分!)
      文章:266
      积分:1911
      门派:Lilybbs.net
      注册:2005/3/11

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给pennyliang发送一个短消息 把pennyliang加入好友 查看pennyliang的个人资料 搜索pennyliang在『 软件工程论坛 』 的所有贴子 引用回复这个贴子 回复这个贴子 查看pennyliang的博客3
    发贴心情 
    和继承无关,仅仅是由于reference在构造过程中创建导致的.
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/12/31 22:43:00
     
     pennyliang 帅哥哟,离线,有人找我吗?白羊座1979-4-7
      
      
      威望:8
      等级:大二期末(C++考了100分!)
      文章:266
      积分:1911
      门派:Lilybbs.net
      注册:2005/3/11

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给pennyliang发送一个短消息 把pennyliang加入好友 查看pennyliang的个人资料 搜索pennyliang在『 软件工程论坛 』 的所有贴子 引用回复这个贴子 回复这个贴子 查看pennyliang的博客4
    发贴心情 
    这个问题其实有更加深刻的内涵,关于reference和expanded type的区别,这个构造过程其实是在构造阶段构造reference,本身就有点问题的,如果这样的话可以考虑expanded type.就不会出现这种错误了。
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/12/31 22:53:00
     
     GoogleAdSense白羊座1979-4-7
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 软件工程论坛 』 的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/3 6:14:06

    本主题贴数4,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    93.750ms