Question: Let's say I have a simple interface:

```
interface IGroupBy {
  String getGroupById();
}

```

Say I have a list of this:

```
List<IGroupBy> v = List.of();

```

But this means that the list has to implement that interface by name.
But what if I am willing to accept any object that had a method that returns a string with that name?

Is there a way to get structural typing in Java using generics somehow?

```
List<T> v = List.of();

```

and then tell the Java compiler about T? Something like:

```
<T hasInterface:IGroupBy>

```

I suppose one way to get part of the way there is using generics like this:

```
   interface IGroupBy<T> {
      T getGroupById();
   }

```

the remaining part is the method name. But that still means you have to reference the same exact interface by name/package.

Answer: 
Yes, it does, provided you install your dependencies with `npm install` or `yarn install`, but it is not only limited to this.

A call to `require` loads modules from `node_modules` if you specify an argument starting with the name of a module. But, you can also `require` custom modules or exports from other js files relative to your project, e.g. you can `require("./MyModule")`, which will import exports from MyModule.js placed in current directory (the one you keep the js file that calls the `require` in).
Yes it works for all you declare in the `dependencies` object in `package.json`.. Beware that you should use `devDependencies` object and have `key,value` which are dependents for your project..

`dependencies` object is a production ready

`deDependencies` is for development..

I would prefer to place all my `packages` in devDependencies unless it is for production.

you can pull a dependency in two ways -

commonJS way: `require('')`

ES6 way: `import statements..`

Once you have a dependency given in `package.json`
give `npm install` or `yarn install`.

But I would prefer `yarn` over `npm` because `yarn` us faster than `npm`.. And now all the dependencies get downloaded into node\_moudules folder.

example: if you say `require('react')` in your code, it actually reads the dependency from nodu\_modules folder.

To understand the `import`, `require` more you need to know when to have a `named import` and when to have a `default export and then import`..

```
default => export default ...;
 named => export const someData = ...;

```

example#01:

Person.js
=========

```
const person = { name: "firstName" }'
export default person;

```

Now you should use import Person from 'Person'

example#02:

clean.js
========

```
 export const clean = () => ...}
then you should use import { clean } from 'clean'

```

default export:

```
import person from './person';
import prs from './person';

```

named export:

```
import { smth } from './utility';
import { smth as Smth } from './utility';
import * as bundled from './utility';

```