HTML5¼¼Êõ

Android -- ´øÄã´ÓÔ´Âë½Ç¶ÈÁìÎòDagger2ÈëÃŵ½·ÅÆú£¨Ò»£© - °¢´ô¸ç¸ç(3)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-04-21 11:02 ÎÒÒªÆÀÂÛ( )

ÏÈ¿´¿´.create·½·¨£¬¿ÉÒÔ¿´µ½¾ÍÊǺܼòµ¥µÄnew Teacher_MembersInjector £¬Ï൱ÓÚ³õʼ»¯ÁËһЩ³ÉÔ±±äÁ¿studentProvider £¬ÖÁÓÚstudentProvider ÊÇʲô£¬´Ó×ÖÃæµÄÒâ˼ÉÏÀ´¿´ÊÇÎÒÃÇstudentµÄÌṩÕߣ¬ÄÇôÊÇʱºòÎÒÃǾÍ

¡¡¡¡ÏÈ¿´¿´.create·½·¨£¬¿ÉÒÔ¿´µ½¾ÍÊǺܼòµ¥µÄnew Teacher_MembersInjector £¬Ï൱ÓÚ³õʼ»¯ÁËһЩ³ÉÔ±±äÁ¿studentProvider £¬ÖÁÓÚstudentProvider ÊÇʲô£¬´Ó×ÖÃæµÄÒâ˼ÉÏÀ´¿´ÊÇÎÒÃÇstudentµÄÌṩÕߣ¬ÄÇôÊÇʱºòÎÒÃǾÍÔÙÀ´¿´¿´Student_Factory.create()·½·¨ÁË£¬ÒòΪÊÇÕâ¸öÀàÌṩÁËstudentProvider ¶ÔÏó

package com.qianmo.rxjavatext; import dagger.internal.Factory; import javax.annotation.Generated; @Generated( value = "dagger.internal.codegen.ComponentProcessor", comments = "https://google.github.io/dagger" ) public enum Student_Factory implements Factory<Student> { INSTANCE; @Override public Student get() { return new Student(); } public static Factory<Student> create() { return INSTANCE; } }

¡¡¡¡ÎѲݣ¬Çë¿´get·½·¨ÖÐµÄ ¡°new Student()¡±´úÂ룬Õâ²»¾ÍÊÇÎÒÃǵÄstudent¶ÔÏóµÄ´´½¨ÂԭÀ´ÄãÔÚÕâÀÔÙ¿´Ò»ÏÂÔÚÄÄÀïµ÷ÓÃÎÒÃǵÄstudentProvider.get·½·¨Äõ½´´½¨µÄStudent¶ÔÏó£¬ÕâʱºòÇë¿´Teacher_MembersInjector.injectMembers()·½·¨£¬¾ßÌå´úÂëÈçÏ£º

@Override public void injectMembers(Teacher instance) { if (instance == null) { throw new NullPointerException("Cannot inject members into a null reference"); } instance.student = studentProvider.get(); }

¡¡¡¡¿´µ½ÎÒÃǵ¹ÊýµÚ¶þÐÐÁËû£¬ÔÚÕâÀïÎÒÃÇÄõ½teacher¶ÔÏó£¬ÉèÖÃËüµÄ³ÉÔ±±äÁ¿student¡£ok£¬µ½ÕâÀïÎÒÃǾͶ®ÁË£¬Õû¸öÂß¼­¾ÍÈ«²¿Í¨ÁË£¬Ê×ÏÈDaggerTeacherComponent.builder().build()Ö´ÐÐÍêÔÚStudent_FactoryÖд´½¨ºÃÁËstudent¶ÔÏó£¬È»ºóÔÚµ÷ÓÃinjectA(this)·½·¨£¬½«´´½¨µÄstudent¶ÔÏó·ÅÖõ½teacher¶ÔÏóÖеÄstudentÊôÐÔÉÏ¡£

¡¡¡¡OK£¬µ½ÕâÀïÎÒÃǾͼòµ¥µÄÁ˽âÁËDagger2µÄʹÓÃÁË£¬Ð´µ½ÕâÀïƪ·ùÒѾ­±È½Ï³¤ÁË£¬ËùÒÔÎÒ´òËãÓÃÈýƪÎÄÕÂÀ´ºÍ´ó¼Ò³Ô͸Dagger2£¬ºÍ´ó¼ÒÒ»Æð´ÓÔ´ÂëÈë¿Óµ½Ìø¿Ó£¬×îºó£¬»¹ÓÐÒ»¸öºÜ¹Ø¼üÊÂÍü˵ÁË£º×î½ü´òËã´ÇÖ°»Ø±±¾©£¬ÓÐûÓдóÉñͬѧÍƼö¹¤×÷£¬´ø´øСµÜ°¡

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • Android ´úÂë¿â£¨×Ô¶¨ÒåÒ»Ì× DialogͨÓÃÌáʾ¿ò £© - ССÇéÒâ

    Android ´úÂë¿â£¨×Ô¶¨ÒåÒ»Ì× DialogͨÓÃÌáʾ¿ò £© - ССÇéÒâ

    2017-04-21 11:01

  • ASP.NET Core MVC Ô´Âëѧϰ£ºÏê½â Action µÄ¼¤»î - Savorboard

    ASP.NET Core MVC Ô´Âëѧϰ£ºÏê½â Action µÄ¼¤»î - Savorboard

    2017-04-14 13:04

  • ³ÌÐòÔ±´øÄãÒ»²½²½·ÖÎöAIÈçºÎÍæFlappyBird - yhthu

    ³ÌÐòÔ±´øÄãÒ»²½²½·ÖÎöAIÈçºÎÍæFlappyBird - yhthu

    2017-04-13 09:03

  • ³µ´ó°ôdz̸jQueryÔ´Â루¶þ£© - ³µ´ó°ô

    ³µ´ó°ôdz̸jQueryÔ´Â루¶þ£© - ³µ´ó°ô

    2017-04-02 10:07

ÍøÓѵãÆÀ
ª