{"id":1834,"date":"2013-10-03T09:04:51","date_gmt":"2013-10-02T21:04:51","guid":{"rendered":"https:\/\/www.deltics.co.nz\/blog\/?p=1834"},"modified":"2013-10-03T09:08:18","modified_gmt":"2013-10-02T21:08:18","slug":"to-init-or-not-to-init-that-is-the-correction","status":"publish","type":"post","link":"https:\/\/www.deltics.co.nz\/blog\/posts\/1834\/","title":{"rendered":"To init() or Not to Init(), That is the Correction"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\"> &lt; 1<\/span> <span class=\"rt-label rt-postfix\">minute]<\/span><\/span><p>The short answer is:  Yes, <strong>init()<\/strong><\/p>\n<p>In <a href=\"https:\/\/www.deltics.co.nz\/blog\/posts\/1817\">a previous post<\/a> I lamented the fact [<em>cough<\/em> &#8211; Ed] that some Java class imports appeared to support the underlying Java constructors via an <code class=\"\" data-line=\"\">init()<\/code> method, where others did not.  This wasn&#8217;t a &#8220;fact&#8221; at all.  It was a misunderstanding based on an incomplete grasp of the machinations of the Java class import mechanism in the <strong>AndroidAPI<\/strong> units.<\/p>\n<p><!--more--><\/p>\n<p>In the code that was presented as part of that post, I demonstrated the construction of a <strong>JIntentFilter<\/strong> followed by separate initialisation.  This can actually be achieved more directly.<\/p>\n<p>Code completion offered only a parameterless constructor (<code class=\"\" data-line=\"\">Create<\/code>) on the <strong>TJIntentFilter<\/strong> class which I incorrectly took to represent the Java class I was working with (<strong>IntentFilter<\/strong>).<\/p>\n<p>It is in fact only a wrapper around that class, constructed by the <strong>TJavaGenericImport<\/strong> base class.<\/p>\n<p>The wrapper exposes the members of the enclosed Java Class through the <strong>JavaClass<\/strong> member.  On this member are to be found the Java constructors in the form of appropriately overloaded <code class=\"\" data-line=\"\">init<\/code> methods.<\/p>\n<p>So this code:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n  filter := TJIntentFilter.Create;\r\n  filter.addAction(TJIntent.JavaClass.ACTION_BATTERY_CHANGED);\r\n<\/pre>\n<p>Is more properly written as:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n  filter := TJIntentFilter.JavaClass.init(TJIntent.JavaClass.ACTION_BATTERY_CHANGED);\r\n<\/pre>\n<p>Which is even uglier and less Pascal&#8217;ly than ever, imho, but does at least mean that you can consistently apply this constructor pattern when instantiating imported Java classes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\"> &lt; 1<\/span> <span class=\"rt-label rt-postfix\">minute]<\/span><\/span>The short answer is: Yes, init() In a previous post I lamented the fact [cough &#8211; Ed] that some Java class imports appeared to support the underlying Java constructors via an init() method, where others did not. This wasn&#8217;t a &#8220;fact&#8221; at all. It was a misunderstanding based on an incomplete grasp of the machinations [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[212,4],"tags":[153,292,225,227],"class_list":["post-1834","post","type-post","status-publish","format-standard","hentry","category-android-2","category-delphi","tag-android","tag-delphi","tag-java","tag-tjavagenericimport"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-tA","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/comments?post=1834"}],"version-history":[{"count":2,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1834\/revisions"}],"predecessor-version":[{"id":1838,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1834\/revisions\/1838"}],"wp:attachment":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=1834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=1834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=1834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}