mirror of
https://github.com/HighCapable/KavaRef.git
synced 2025-09-06 10:45:27 +08:00
111 lines
60 KiB
HTML
111 lines
60 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en-US">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<meta name="generator" content="VuePress 2.0.0-rc.0">
|
|
<style>
|
|
:root {
|
|
--c-bg: #fff;
|
|
}
|
|
html.dark {
|
|
--c-bg: #22272e;
|
|
}
|
|
html, body {
|
|
background-color: var(--c-bg);
|
|
}
|
|
</style>
|
|
<script>
|
|
const userMode = localStorage.getItem('vuepress-color-scheme');
|
|
const systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
if (userMode === 'dark' || (userMode !== 'light' && systemDarkMode)) {
|
|
document.documentElement.classList.toggle('dark', true);
|
|
}
|
|
</script>
|
|
<link rel="icon" href="/KavaRef/images/logo.svg"><title>kavaref-extension | KavaRef</title><meta name="description" content="A modernizing Java Reflection with Kotlin">
|
|
<link rel="preload" href="/KavaRef/assets/style-_yWeWZ9-.css" as="style"><link rel="stylesheet" href="/KavaRef/assets/style-_yWeWZ9-.css">
|
|
<link rel="modulepreload" href="/KavaRef/assets/app-mh6GuRj9.js"><link rel="modulepreload" href="/KavaRef/assets/kavaref-extension.html-T1UdfLZL.js"><link rel="modulepreload" href="/KavaRef/assets/kavaref-extension.html-IUNV997z.js">
|
|
<link rel="prefetch" href="/KavaRef/assets/index.html-Ov_ij_gv.js" as="script"><link rel="prefetch" href="/KavaRef/assets/index.html-CFZQ5XVF.js" as="script"><link rel="prefetch" href="/KavaRef/assets/index.html-W7aZ6bnM.js" as="script"><link rel="prefetch" href="/KavaRef/assets/migration.html-MsUQmaeZ.js" as="script"><link rel="prefetch" href="/KavaRef/assets/processor-resolvers.html-YYDSqVfs.js" as="script"><link rel="prefetch" href="/KavaRef/assets/r8-proguard.html-oPUAmrol.js" as="script"><link rel="prefetch" href="/KavaRef/assets/about.html-9T1xc62o.js" as="script"><link rel="prefetch" href="/KavaRef/assets/changelog.html-tvXK8X7C.js" as="script"><link rel="prefetch" href="/KavaRef/assets/contacts.html-L9oNW9KK.js" as="script"><link rel="prefetch" href="/KavaRef/assets/future.html-8f4lJIja.js" as="script"><link rel="prefetch" href="/KavaRef/assets/home.html-nmYQl1IQ.js" as="script"><link rel="prefetch" href="/KavaRef/assets/quick-start.html-Qcmp4XDc.js" as="script"><link rel="prefetch" href="/KavaRef/assets/kavaref-core.html-Dt130sIh.js" as="script"><link rel="prefetch" href="/KavaRef/assets/about.html-wsvWpCuP.js" as="script"><link rel="prefetch" href="/KavaRef/assets/changelog.html-rnn3UCr6.js" as="script"><link rel="prefetch" href="/KavaRef/assets/contacts.html-yC5Cjm9f.js" as="script"><link rel="prefetch" href="/KavaRef/assets/future.html-TYRCoFGP.js" as="script"><link rel="prefetch" href="/KavaRef/assets/migration.html-c2_NChU1.js" as="script"><link rel="prefetch" href="/KavaRef/assets/processor-resolvers.html-LDkOJBjK.js" as="script"><link rel="prefetch" href="/KavaRef/assets/r8-proguard.html-OS5OKrdo.js" as="script"><link rel="prefetch" href="/KavaRef/assets/home.html-6hAcbiCY.js" as="script"><link rel="prefetch" href="/KavaRef/assets/quick-start.html-XeqtvFBe.js" as="script"><link rel="prefetch" href="/KavaRef/assets/kavaref-core.html-Ffv_VDo5.js" as="script"><link rel="prefetch" href="/KavaRef/assets/kavaref-extension.html-fHAqKHa2.js" as="script"><link rel="prefetch" href="/KavaRef/assets/404.html-6Yl8cQE3.js" as="script"><link rel="prefetch" href="/KavaRef/assets/index.html-NhRLIkuI.js" as="script"><link rel="prefetch" href="/KavaRef/assets/index.html-8K8ZL9xM.js" as="script"><link rel="prefetch" href="/KavaRef/assets/index.html-5KLsgsb9.js" as="script"><link rel="prefetch" href="/KavaRef/assets/migration.html-Ye0WsuNZ.js" as="script"><link rel="prefetch" href="/KavaRef/assets/processor-resolvers.html-27WP0yfV.js" as="script"><link rel="prefetch" href="/KavaRef/assets/r8-proguard.html-dK3W_u38.js" as="script"><link rel="prefetch" href="/KavaRef/assets/about.html-GB22dzJZ.js" as="script"><link rel="prefetch" href="/KavaRef/assets/changelog.html-6g49VohJ.js" as="script"><link rel="prefetch" href="/KavaRef/assets/contacts.html-8ISTVPQY.js" as="script"><link rel="prefetch" href="/KavaRef/assets/future.html-3Px710os.js" as="script"><link rel="prefetch" href="/KavaRef/assets/home.html-Z0EW9e5o.js" as="script"><link rel="prefetch" href="/KavaRef/assets/quick-start.html-q_jDDuWq.js" as="script"><link rel="prefetch" href="/KavaRef/assets/kavaref-core.html-tTFO-8Za.js" as="script"><link rel="prefetch" href="/KavaRef/assets/about.html-yDUNfYYH.js" as="script"><link rel="prefetch" href="/KavaRef/assets/changelog.html-vN7TJtDC.js" as="script"><link rel="prefetch" href="/KavaRef/assets/contacts.html-YmutBtVn.js" as="script"><link rel="prefetch" href="/KavaRef/assets/future.html-aZj72rRC.js" as="script"><link rel="prefetch" href="/KavaRef/assets/migration.html-GY17HjTz.js" as="script"><link rel="prefetch" href="/KavaRef/assets/processor-resolvers.html-9c-bJv94.js" as="script"><link rel="prefetch" href="/KavaRef/assets/r8-proguard.html-dGWuVyvG.js" as="script"><link rel="prefetch" href="/KavaRef/assets/home.html-ZBkLyAmP.js" as="script"><link rel="prefetch" href="/KavaRef/assets/quick-start.html-URixYC24.js" as="script"><link rel="prefetch" href="/KavaRef/assets/kavaref-core.html-4qPYzqqN.js" as="script"><link rel="prefetch" href="/KavaRef/assets/kavaref-extension.html-Is97lgJ-.js" as="script"><link rel="prefetch" href="/KavaRef/assets/404.html-QklWHkM6.js" as="script">
|
|
</head>
|
|
<body>
|
|
<div id="app"><!--[--><div class="theme-container"><!--[--><header class="navbar"><div class="toggle-sidebar-button" title="toggle sidebar" aria-expanded="false" role="button" tabindex="0"><div class="icon" aria-hidden="true"><span></span><span></span><span></span></div></div><span><a href="/KavaRef/en/" class=""><img class="logo" src="/KavaRef/images/logo.svg" alt="KavaRef"><span class="site-name can-hide">KavaRef</span></a></span><div class="navbar-items-wrapper" style=""><!--[--><!--]--><nav class="navbar-items can-hide"><!--[--><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="Navigation"><span class="title">Navigation</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="Navigation"><span class="title">Navigation</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>Get Started</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/guide/home.html" class="" aria-label="Introduction"><!--[--><!--]--> Introduction <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/guide/quick-start.html" class="" aria-label="Quick Start"><!--[--><!--]--> Quick Start <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>Libraries</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/library/kavaref-core.html" class="" aria-label="kavaref-core"><!--[--><!--]--> kavaref-core <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html" class="router-link-active router-link-exact-active router-link-active" aria-label="kavaref-extension"><!--[--><!--]--> kavaref-extension <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>Configs</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/config/r8-proguard.html" class="" aria-label="R8 & ProGuard Obfuscation"><!--[--><!--]--> R8 & ProGuard Obfuscation <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/config/processor-resolvers.html" class="" aria-label="Third-party Member Resolvers"><!--[--><!--]--> Third-party Member Resolvers <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/config/migration.html" class="" aria-label="Migration to KavaRef"><!--[--><!--]--> Migration to KavaRef <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>About</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/about/changelog.html" class="" aria-label="Changelog"><!--[--><!--]--> Changelog <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/about/future.html" class="" aria-label="Looking Toward the Future"><!--[--><!--]--> Looking Toward the Future <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/about/contacts.html" class="" aria-label="Contact Us"><!--[--><!--]--> Contact Us <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/about/about.html" class="" aria-label="About This Document"><!--[--><!--]--> About This Document <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><!--]--></ul></div></div><div class="navbar-item"><a href="/KavaRef/en/about/contacts" class="" aria-label="Contact Us"><!--[--><!--]--> Contact Us <!--[--><!--]--></a></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="Select language"><span class="title">English (US)</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="Select language"><span class="title">English (US)</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html" class="router-link-active router-link-exact-active router-link-active" aria-label="English"><!--[--><!--]--> English <!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a href="/KavaRef/zh-cn/library/kavaref-extension.html" class="" aria-label="简体中文"><!--[--><!--]--> 简体中文 <!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-item"><a class="external-link" href="https://github.com/HighCapable/KavaRef" rel="noopener noreferrer" target="_blank" aria-label="GitHub"><!--[--><!--]--> GitHub <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><button class="toggle-color-mode-button" title="toggle color mode"><svg style="" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z" fill="currentColor"></path><path d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z" fill="currentColor"></path><path d="M2 15.005h5v2H2z" fill="currentColor"></path><path d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 25.005h2v5h-2z" fill="currentColor"></path><path d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z" fill="currentColor"></path><path d="M25 15.005h5v2h-5z" fill="currentColor"></path><path d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 2.005h2v5h-2z" fill="currentColor"></path></svg><svg style="display:none;" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z" fill="currentColor"></path></svg></button><form class="search-box" role="search"><input type="search" placeholder="Search" autocomplete="off" spellcheck="false" value><!----></form></div></header><!--]--><div class="sidebar-mask"></div><!--[--><aside class="sidebar"><nav class="navbar-items"><!--[--><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="Navigation"><span class="title">Navigation</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="Navigation"><span class="title">Navigation</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>Get Started</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/guide/home.html" class="" aria-label="Introduction"><!--[--><!--]--> Introduction <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/guide/quick-start.html" class="" aria-label="Quick Start"><!--[--><!--]--> Quick Start <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>Libraries</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/library/kavaref-core.html" class="" aria-label="kavaref-core"><!--[--><!--]--> kavaref-core <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html" class="router-link-active router-link-exact-active router-link-active" aria-label="kavaref-extension"><!--[--><!--]--> kavaref-extension <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>Configs</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/config/r8-proguard.html" class="" aria-label="R8 & ProGuard Obfuscation"><!--[--><!--]--> R8 & ProGuard Obfuscation <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/config/processor-resolvers.html" class="" aria-label="Third-party Member Resolvers"><!--[--><!--]--> Third-party Member Resolvers <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/config/migration.html" class="" aria-label="Migration to KavaRef"><!--[--><!--]--> Migration to KavaRef <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>About</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/about/changelog.html" class="" aria-label="Changelog"><!--[--><!--]--> Changelog <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/about/future.html" class="" aria-label="Looking Toward the Future"><!--[--><!--]--> Looking Toward the Future <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/about/contacts.html" class="" aria-label="Contact Us"><!--[--><!--]--> Contact Us <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/KavaRef/en/about/about.html" class="" aria-label="About This Document"><!--[--><!--]--> About This Document <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><!--]--></ul></div></div><div class="navbar-item"><a href="/KavaRef/en/about/contacts" class="" aria-label="Contact Us"><!--[--><!--]--> Contact Us <!--[--><!--]--></a></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="Select language"><span class="title">English (US)</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="Select language"><span class="title">English (US)</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html" class="router-link-active router-link-exact-active router-link-active" aria-label="English"><!--[--><!--]--> English <!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a href="/KavaRef/zh-cn/library/kavaref-extension.html" class="" aria-label="简体中文"><!--[--><!--]--> 简体中文 <!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-item"><a class="external-link" href="https://github.com/HighCapable/KavaRef" rel="noopener noreferrer" target="_blank" aria-label="GitHub"><!--[--><!--]--> GitHub <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><ul class="sidebar-items"><!--[--><li><p tabindex="0" class="sidebar-item sidebar-heading collapsible">Get Started <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/KavaRef/en/guide/home.html" class="sidebar-item" aria-label="Introduction"><!--[--><!--]--> Introduction <!--[--><!--]--></a><!----></li><li><a href="/KavaRef/en/guide/quick-start.html" class="sidebar-item" aria-label="Quick Start"><!--[--><!--]--> Quick Start <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item sidebar-heading active collapsible">Libraries <span class="down arrow"></span></p><ul style="" class="sidebar-item-children"><!--[--><li><a href="/KavaRef/en/library/kavaref-core.html" class="sidebar-item" aria-label="kavaref-core"><!--[--><!--]--> kavaref-core <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html" class="router-link-active router-link-exact-active router-link-active sidebar-item active" aria-label="kavaref-extension"><!--[--><!--]--> kavaref-extension <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#configure-dependency" class="router-link-active router-link-exact-active sidebar-item" aria-label="Configure Dependency"><!--[--><!--]--> Configure Dependency <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#sweetdependency-recommended" class="router-link-active router-link-exact-active sidebar-item" aria-label="SweetDependency (Recommended)"><!--[--><!--]--> SweetDependency (Recommended) <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#version-catalog" class="router-link-active router-link-exact-active sidebar-item" aria-label="Version Catalog"><!--[--><!--]--> Version Catalog <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#traditional-method" class="router-link-active router-link-exact-active sidebar-item" aria-label="Traditional Method"><!--[--><!--]--> Traditional Method <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#function-introduction" class="router-link-active router-link-exact-active sidebar-item" aria-label="Function Introduction"><!--[--><!--]--> Function Introduction <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#class-extensions" class="router-link-active router-link-exact-active sidebar-item" aria-label="Class Extensions"><!--[--><!--]--> Class Extensions <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#array-class-extensions" class="router-link-active router-link-exact-active sidebar-item" aria-label="Array Class Extensions"><!--[--><!--]--> Array Class Extensions <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#member-extensions" class="router-link-active router-link-exact-active sidebar-item" aria-label="Member Extensions"><!--[--><!--]--> Member Extensions <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#type-extensions" class="router-link-active router-link-exact-active sidebar-item" aria-label="Type Extensions"><!--[--><!--]--> Type Extensions <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/KavaRef/en/library/kavaref-extension.html#java-wrapper-classes-extensions" class="router-link-active router-link-exact-active sidebar-item" aria-label="Java Wrapper Classes Extensions"><!--[--><!--]--> Java Wrapper Classes Extensions <!--[--><!--]--></a><!----></li><!--]--></ul></li><!--]--></ul></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item sidebar-heading collapsible">Configs <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/KavaRef/en/config/r8-proguard.html" class="sidebar-item" aria-label="R8 & ProGuard Obfuscation"><!--[--><!--]--> R8 & ProGuard Obfuscation <!--[--><!--]--></a><!----></li><li><a href="/KavaRef/en/config/processor-resolvers.html" class="sidebar-item" aria-label="Third-party Member Resolvers"><!--[--><!--]--> Third-party Member Resolvers <!--[--><!--]--></a><!----></li><li><a href="/KavaRef/en/config/migration.html" class="sidebar-item" aria-label="Migration to KavaRef"><!--[--><!--]--> Migration to KavaRef <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item sidebar-heading collapsible">About <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/KavaRef/en/about/changelog.html" class="sidebar-item" aria-label="Changelog"><!--[--><!--]--> Changelog <!--[--><!--]--></a><!----></li><li><a href="/KavaRef/en/about/future.html" class="sidebar-item" aria-label="Looking Toward the Future"><!--[--><!--]--> Looking Toward the Future <!--[--><!--]--></a><!----></li><li><a href="/KavaRef/en/about/contacts.html" class="sidebar-item" aria-label="Contact Us"><!--[--><!--]--> Contact Us <!--[--><!--]--></a><!----></li><li><a href="/KavaRef/en/about/about.html" class="sidebar-item" aria-label="About This Document"><!--[--><!--]--> About This Document <!--[--><!--]--></a><!----></li><!--]--></ul></li><!--]--></ul><!--[--><!--]--></aside><!--]--><!--[--><main class="page"><!--[--><!--]--><div class="theme-default-content"><!--[--><!--]--><div><h1 id="kavaref-extension" tabindex="-1"><a class="header-anchor" href="#kavaref-extension" aria-hidden="true">#</a> kavaref-extension</h1><p><img src="https://img.shields.io/maven-central/v/com.highcapable.kavaref/kavaref-extension?logo=apachemaven&logoColor=orange&style=flat-square" alt="Maven Central"><span style="margin-left:5px;"></span><img src="https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fraw.githubusercontent.com%2FHighCapable%2Fmaven-repository%2Frefs%2Fheads%2Fmain%2Frepository%2Freleases%2Fcom%2Fhighcapable%2Fkavaref%2Fkavaref-extension%2Fmaven-metadata.xml&logo=apachemaven&logoColor=orange&label=highcapable-maven-releases&style=flat-square" alt="Maven metadata URL"></p><p>This is an extended dependency for KavaRef-related features.</p><h2 id="configure-dependency" tabindex="-1"><a class="header-anchor" href="#configure-dependency" aria-hidden="true">#</a> Configure Dependency</h2><p>You can add this module to your project using the following method.</p><h3 id="sweetdependency-recommended" tabindex="-1"><a class="header-anchor" href="#sweetdependency-recommended" aria-hidden="true">#</a> SweetDependency (Recommended)</h3><p>Add dependency in your project's <code>SweetDependency</code> configuration file.</p><div class="language-yaml line-numbers-mode" data-ext="yml"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#8DDB8C;">libraries</span><span style="color:#ADBAC7;">:</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#8DDB8C;">com.highcapable.kavaref</span><span style="color:#ADBAC7;">:</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#8DDB8C;">kavaref-extension</span><span style="color:#ADBAC7;">:</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#8DDB8C;">version</span><span style="color:#ADBAC7;">: </span><span style="color:#96D0FF;">+</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Configure dependency in your project's <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">implementation</span><span style="color:#ADBAC7;">(com.highcapable.kavaref.kavaref.extension)</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="version-catalog" tabindex="-1"><a class="header-anchor" href="#version-catalog" aria-hidden="true">#</a> Version Catalog</h3><p>Add dependency in your project's <code>gradle/libs.versions.toml</code>.</p><div class="language-toml line-numbers-mode" data-ext="toml"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">[</span><span style="color:#F69D50;">versions</span><span style="color:#ADBAC7;">]</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">kavaref-extension = </span><span style="color:#96D0FF;">"<version>"</span></span>
|
|
<span class="line"></span>
|
|
<span class="line"><span style="color:#ADBAC7;">[</span><span style="color:#F69D50;">libraries</span><span style="color:#ADBAC7;">]</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">kavaref-extension = { module = </span><span style="color:#96D0FF;">"com.highcapable.kavaref:kavaref-extension"</span><span style="color:#ADBAC7;">, version.ref = </span><span style="color:#96D0FF;">"kavaref-extension"</span><span style="color:#ADBAC7;"> }</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Configure dependency in your project's <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">implementation</span><span style="color:#ADBAC7;">(libs.kavaref.extension)</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Please change <code><version></code> to the version displayed at the top of this document.</p><h3 id="traditional-method" tabindex="-1"><a class="header-anchor" href="#traditional-method" aria-hidden="true">#</a> Traditional Method</h3><p>Configure dependency in your project's <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">implementation</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"com.highcapable.kavaref:kavaref-extension:<version>"</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Please change <code><version></code> to the version displayed at the top of this document.</p><h2 id="function-introduction" tabindex="-1"><a class="header-anchor" href="#function-introduction" aria-hidden="true">#</a> Function Introduction</h2><p>You can view the KDoc <a href="https://highcapable.github.io/KavaRef/KDoc/kavaref-extension" target="_blank" rel="noopener noreferrer">click here<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span></a>.</p><h3 id="class-extensions" tabindex="-1"><a class="header-anchor" href="#class-extensions" aria-hidden="true">#</a> Class Extensions</h3><p>KavaRef provides some extensions that are more convenient when dealing with <code>Class</code> objects.</p><p>KavaRef also adds <code>KClass</code> extensions to the <code>Class</code> extensions, which is used to call <code>KClass.java</code>, making it more concise than using <code>Some::class.java</code> directly.</p><h4 id="create-class-object" tabindex="-1"><a class="header-anchor" href="#create-class-object" aria-hidden="true">#</a> Create Class Object</h4><p>For example, we need to create a <code>Class</code> object using the string class name.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClass </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.MyClass"</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">toClass</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"><span style="color:#768390;">// You can use a method with OrNull suffix to return null</span></span>
|
|
<span class="line"><span style="color:#768390;">// when the Class is not found instead of throwing an exception.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClassOrNull </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.MyClass"</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">toClassOrNull</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>These methods use <code>ClassLoaderProvider</code> to get the default <code>ClassLoader</code>, you can set the default <code>ClassLoader</code> to affect global functionality.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">ClassLoaderProvider.classLoader </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">MyCustomClassLoader</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>You can also manually pass a <code>ClassLoader</code> parameter to the <code>toClass</code> method to specify which <code>ClassLoader</code> to use.</p><h4 id="class-object-reference" tabindex="-1"><a class="header-anchor" href="#class-object-reference" aria-hidden="true">#</a> Class Object Reference</h4><p>Referring to a Java Class in Kotlin requires writing a very long statement, such as <code>MyClass::class.java</code>, which you can simplify in the following way.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClass </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">classOf</span><span style="color:#ADBAC7;"><</span><span style="color:#F69D50;">MyClass</span><span style="color:#ADBAC7;">>()</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>You can use the <code>isSubclassOf</code> method to determine whether a <code>Class</code> is another <code>Class</code> subclass.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> isSubclass </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> MyClass::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;"> isSubclassOf MySuperClass::</span><span style="color:#DCBDFB;">class</span></span>
|
|
<span class="line"><span style="color:#768390;">// Of course, it also has a corresponding antonym of judgment.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> isNotSubclass </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> MyClass::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;"> isNotSubclassOf MySuperClass::</span><span style="color:#DCBDFB;">class</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You can also use the <code>hasSuperclass</code> and <code>hasInterfaces</code> methods to determine whether a <code>Class</code> has a superclass or an interface.</p><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>The <code>Class</code> passed in by the <code>classOf</code> method will perform unboxing of Java wrapper classes by default, whether you pass in something like <code>kotlin.Boolean</code> or <code>java.lang.Boolean</code> (see <a href="#java-wrapper-classes-extensions">Java Wrapper Classes Extensions</a> below), If you need to avoid the incoming <code>Class</code> being unboxed into primitive types, you need to explicitly set the <code>primitiveType = false</code> parameter.</p></div><h4 id="create-new-instance" tabindex="-1"><a class="header-anchor" href="#create-new-instance" aria-hidden="true">#</a> Create New Instance</h4><p>KavaRef provides a way for <code>Class</code> to easily create a new instance. You don't need to consider the type of constructing parameters, you just need to pass in the corresponding parameters to create a new instance immediately.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClass </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> MyClass::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">createInstance</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"Hello"</span><span style="color:#ADBAC7;">, </span><span style="color:#6CB6FF;">123</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"><span style="color:#768390;">// You can also use a method with the OrNull suffix to return null</span></span>
|
|
<span class="line"><span style="color:#768390;">// when creation fails instead of throwing an exception.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClassOrNull </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> MyClass::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">createInstanceOrNull</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"Hello"</span><span style="color:#ADBAC7;">, </span><span style="color:#6CB6FF;">123</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"><span style="color:#768390;">// The createInstance method only filters public constructors by default.</span></span>
|
|
<span class="line"><span style="color:#768390;">// If you need to call non-public constructors, please set isPublic = false.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClassWithPrivateConstructor </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> MyClass::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">createInstance</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"Private!"</span><span style="color:#ADBAC7;">, isPublic </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">false</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"><span style="color:#768390;">// If you want to specify the type to create an instance to use another type,</span></span>
|
|
<span class="line"><span style="color:#768390;">// you can use the following method.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> mySuperClass </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> MyClass::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">createInstanceAsType</span><span style="color:#ADBAC7;"><</span><span style="color:#F69D50;">MySuperClass</span><span style="color:#ADBAC7;">>(</span><span style="color:#96D0FF;">"Hello"</span><span style="color:#ADBAC7;">, </span><span style="color:#6CB6FF;">123</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"><span style="color:#768390;">// Similarly, you can use a method with the OrNull suffix to return null when</span></span>
|
|
<span class="line"><span style="color:#768390;">// creation fails instead of throwing an exception.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> mySuperClassOrNull </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> MyClass::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;">.</span><span style="color:#DCBDFB;">createInstanceAsTypeOrNull</span><span style="color:#ADBAC7;"><</span><span style="color:#F69D50;">MySuperClass</span><span style="color:#ADBAC7;">>(</span><span style="color:#96D0FF;">"Hello"</span><span style="color:#ADBAC7;">, </span><span style="color:#6CB6FF;">123</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>After the <code>createInstance</code> method is successfully matched once, it will cache the results to prevent performance losses caused by duplicated reflections. It is thread-safe and you can use it in any standard scenario with confidence.</p></div><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>When you pass in a parameter with <code>null</code>, KavaRef tries to use it as part of the matchable condition (vague condition), and the accuracy may decrease.</p><p>The <code>createInstance</code> method does not allow all parameters to be <code>null</code> (the conditions are completely vague), and an exception will be thrown directly because this situation cannot be determined which instance to create.</p></div><h4 id="class-modifier" tabindex="-1"><a class="header-anchor" href="#class-modifier" aria-hidden="true">#</a> Class Modifier</h4><p>KavaRef also extends <code>Modifier</code>, you can directly use <code>Class.isPublic</code> and other methods to judge a <code>Class</code> modifier.</p><h4 id="variousclass" tabindex="-1"><a class="header-anchor" href="#variousclass" aria-hidden="true">#</a> VariousClass</h4><p>KavaRef provides the <code>VariousClass</code> class to load the <code>Class</code> object with an indeterminate full class name and return the first match successfully.</p><p>This feature is usually used for class names in Android apps that are obfuscated by R8.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume that in version A, this class is com.example.a,</span></span>
|
|
<span class="line"><span style="color:#768390;">// In version B, this class is com.example.b.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClass </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">VariousClass</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"com.example.a"</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">"com.example.b"</span><span style="color:#ADBAC7;">).</span><span style="color:#DCBDFB;">load</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"><span style="color:#768390;">// You can also use a method with the suffix OrNull to return null</span></span>
|
|
<span class="line"><span style="color:#768390;">// instead of throwing an exception if Class is not found.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClassOrNull </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">VariousClass</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"com.example.a"</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">"com.example.b"</span><span style="color:#ADBAC7;">).</span><span style="color:#DCBDFB;">loadOrNull</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="lazy-loading-class-object" tabindex="-1"><a class="header-anchor" href="#lazy-loading-class-object" aria-hidden="true">#</a> Lazy Loading Class Object</h4><p>KavaRef provides the <code>LazyClass</code> class to lazy loading the <code>Class</code> object.</p><p>You can load <code>Class</code> when needed, instead of loading it immediately when created, which can solve some <code>Class</code> that need to be loaded when run or run to specific conditions.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Define a Class that cannot be loaded for null and hosts it to myClass.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClass </span><span style="color:#F47067;">by</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">lazyClass</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"com.example.MyClass"</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"><span style="color:#768390;">// Define a Class that can be loaded for null delay and host it to myClassOrNull.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClassOrNull </span><span style="color:#F47067;">by</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">lazyClassOrNull</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"com.example.MyClass"</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"><span style="color:#768390;">// It can also support incoming VariousClass.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> otherClassOrNull </span><span style="color:#F47067;">by</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">lazyClassOrNull</span><span style="color:#ADBAC7;">(</span><span style="color:#DCBDFB;">VariousClass</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"com.example.a"</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">"com.example.b"</span><span style="color:#ADBAC7;">))</span></span>
|
|
<span class="line"><span style="color:#768390;">// Called and loaded when needed.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">myClass.</span><span style="color:#DCBDFB;">resolve</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">myClassOrNull?.</span><span style="color:#DCBDFB;">resolve</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">otherClassOrNull?.</span><span style="color:#DCBDFB;">resolve</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="classloader-extensions" tabindex="-1"><a class="header-anchor" href="#classloader-extensions" aria-hidden="true">#</a> ClassLoader Extensions</h4><p>KavaRef also provides some practical extension methods for <code>ClassLoader</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume that's your ClassLoader.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> classLoader: </span><span style="color:#F69D50;">ClassLoader</span></span>
|
|
<span class="line"><span style="color:#768390;">// Load a Class and return null if the load fails.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClassOrNull </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> classLoader.</span><span style="color:#DCBDFB;">loadClassOrNull</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"com.example.MyClass"</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"><span style="color:#768390;">// Determine whether this Class exists in the current ClassLoader.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> isClassExists </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> classLoader.</span><span style="color:#DCBDFB;">hasClass</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">"com.example.MyClass"</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="array-class-extensions" tabindex="-1"><a class="header-anchor" href="#array-class-extensions" aria-hidden="true">#</a> Array Class Extensions</h3><p>In Java, the <code>Class</code> object of an array is a special <code>Class</code> object, and usually we create it as follows.</p><p>For example, create a <code>Class</code> object of <code>java.lang.String[]</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> arrayClass </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> java.lang.reflect.Array.</span><span style="color:#DCBDFB;">newInstance</span><span style="color:#ADBAC7;">(String::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;">.java, </span><span style="color:#6CB6FF;">0</span><span style="color:#ADBAC7;">).javaClass</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>This is very long to write and is not convenient to maintain, so KavaRef provides a way to simplify this process.</p><p>Now, the <code>Class</code> object that creates <code>java.lang.String[]</code> can be written like this.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> arrayClass </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">ArrayClass</span><span style="color:#ADBAC7;">(String::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;">)</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="member-extensions" tabindex="-1"><a class="header-anchor" href="#member-extensions" aria-hidden="true">#</a> Member Extensions</h3><p>KavaRef provides some extension methods to simplify operations on <code>Member</code>.</p><p>You can set its accessibility using the <code>makeAccessible</code> method on any <code>Member</code> object.</p><p>It will take effect if <code>Member</code> is the <code>AccessibleObject</code> type.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Suppose this is your current Member object.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> method: </span><span style="color:#F69D50;">Method</span></span>
|
|
<span class="line"><span style="color:#768390;">// Make method is accessible.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">method.</span><span style="color:#DCBDFB;">makeAccessible</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Similarly, KavaRef also extends <code>Modifier</code>, and you can directly use <code>Member.isPublic</code> and other methods to judge a <code>Member</code> modifier.</p><h3 id="type-extensions" tabindex="-1"><a class="header-anchor" href="#type-extensions" aria-hidden="true">#</a> Type Extensions</h3><p>When manipulating types or generic types in Java, you usually need to use the <code>Type</code> interface and its subinterface to handle it.</p><p>KavaRef provides some extension methods to simplify operations on <code>Type</code>.</p><p>For example, you can convert a <code>Type</code> that meets the requirements to a <code>Class</code> object.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> type: </span><span style="color:#F69D50;">Type</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> clazz </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> type.</span><span style="color:#DCBDFB;">toClass</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"><span style="color:#768390;">// You can also use a method with the suffix named OrNull to</span></span>
|
|
<span class="line"><span style="color:#768390;">// return null when the conversion fails instead of throwing an exception.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> clazzOrNull </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> type.</span><span style="color:#DCBDFB;">toClassOrNull</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You can also convert <code>Type</code> that meets the requirements to <code>ParameterizedType</code> object.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> type: </span><span style="color:#F69D50;">Type</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> parameterizedType </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> type.</span><span style="color:#DCBDFB;">asParameterizedType</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"><span style="color:#768390;">// You can also use a method with the suffix named OrNull to</span></span>
|
|
<span class="line"><span style="color:#768390;">// return null when the conversion fails instead of throwing an exception.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> parameterizedTypeOrNull </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> type.</span><span style="color:#DCBDFB;">asParameterizedTypeOrNull</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You can also use the following method to get the generic parameter array in the superclass, which is often used in some superclass and subclass encapsulation operations.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> myClass: </span><span style="color:#F69D50;">Class</span><span style="color:#ADBAC7;"><*></span></span>
|
|
<span class="line"><span style="color:#768390;">// Get the generic parameter array of myClass superclass.</span></span>
|
|
<span class="line"><span style="color:#768390;">// If the acquisition fails or cannot be retrieved, the empty array will be returned.</span></span>
|
|
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> arguments </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> myClass.</span><span style="color:#DCBDFB;">genericSuperclassTypeArguments</span><span style="color:#ADBAC7;">()</span></span>
|
|
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="java-wrapper-classes-extensions" tabindex="-1"><a class="header-anchor" href="#java-wrapper-classes-extensions" aria-hidden="true">#</a> Java Wrapper Classes Extensions</h3><p>In Kotlin, you can directly use <code>Boolean::class</code>, <code>Byte::class</code>, etc. to obtain Java's original types <code>boolean</code> and <code>byte</code> instead of their wrapper classes.</p><p>If you need to get Java wrapper classes, you need to use the complete <code>java.lang.Boolean::class</code>, <code>java.lang.Byte::class</code>, etc. or use <code>Boolean::class.javaObjectType</code>, <code>Byte::class.javaObjectType</code>.</p><p>So, KavaRef provides some type alias to handle Java wrapper classes. Now you only need to prefix <code>J</code> to these types, such as <code>JBoolean::class</code>. It is equivalent to <code>java.lang.Boolean::class</code>, and some types need to be filled in the full name, such as <code>JInteger::class</code>.</p></div><!--[--><!--]--></div><footer class="page-meta"><div class="meta-item edit-link"><a class="external-link meta-item-label" href="https://github.com/HighCapable/KavaRef/edit/main/docs-source/src/en/library/kavaref-extension.md" rel="noopener noreferrer" target="_blank" aria-label="Edit this page on GitHub"><!--[--><!--]--> Edit this page on GitHub <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><div class="meta-item last-updated"><span class="meta-item-label">Last Updated: </span><!----></div><div class="meta-item contributors"><span class="meta-item-label">Contributors: </span><span class="meta-item-info"><!--[--><!--[--><span class="contributor" title="email: qzmmcn@163.com">fankesyooni</span><!----><!--]--><!--]--></span></div></footer><nav class="page-nav"><p class="inner"><span class="prev"><a href="/KavaRef/en/library/kavaref-core.html" class="" aria-label="kavaref-core"><!--[--><!--]--> kavaref-core <!--[--><!--]--></a></span><!----></p></nav><!--[--><!--]--></main><!--]--></div><!----><!--]--></div>
|
|
<script type="module" src="/KavaRef/assets/app-mh6GuRj9.js" defer></script>
|
|
</body>
|
|
</html>
|