Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7999365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:29:08+00:00 2026-06-04T15:29:08+00:00

I am using an API where a trait is given like this: package pkg

  • 0

I am using an API where a trait is given like this:

package pkg

trait Trait { 
  private[pkg] def f = ...
  private[pkg] val content = ...
}

I would like to access the variable content and function f in my code, using the API from a Jar file (so I cannot modify the original code to remove the private definition).

What I was able to come up with as a first solution is to create a new bridge class in the same package, that helps me access the private/protected member functions like this:

package pkg

trait PkgBridge {
  def f = Trait.f
  def getContent(t : Trait) = t.content;
}

This way I can call the package private members from my code.

I was wondering if there is any sophisticated way or common pattern for this kind of situations (like some magic with implicits or something?).

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:29:09+00:00Added an answer on June 4, 2026 at 3:29 pm

    What you are doing works, is probably as good a way to do it as any, and is discouraged.

    If something is package private it is probably an implementation detail for which an interface has not be specified sufficiently well to risk exposing anyone to it or to allow it to be completely private. So be careful! There may be good reason to not do this.

    Aside from reflection, the only way within Scala to get at package private content is to be in that package, so your method is an appropriate one.

    Note that this alternative might be useful as well:

    package pkg {
      trait TraitBridge extends Trait {
        def fBridge = f
        def contentBridge = content
      }
    }
    

    and then you can

    class MyClass extends TraitBridge { ... }
    

    to specifically pick up the extensions that you want to have access to (under alternate names).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using PHP API posts ' likes comes in this detailed format [likes] =>
I'm using FileReader API to read files on local. <input type=file id=filesx name=filesx[] onchange=readmultifiles(this.files)
I am attempting to build an authentication mechanism using API keys for access. As
Using the Play! Framework 1.2.4. I've got a nifty trait that checks an API
I'm writing some Scala code which uses the Apache POI API. I would like
I'd like to accomplish the following in Android using API Level 7: glGet(GL_VIEWPORT, someBuffer)
Here I want to display the JSON content using API key. But I am
I'm creating a small service using api-libraries, such as Twitter. Is it possible to
I'm trying to send post using API feed. I set fields: message , link
I'm using MySQL API's function mysql_real_escape_string() Based on the documentation, it escapes the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.